July 3, 2003

Hungarian Notation

I’ve been using Hungarian Notation in my programming for years, both in my database schemes (SELECT EmployeeID FROM tblEmployees;) and just in my general ASP programming (strFileName = "form.asp"). I’ve been using it pretty much since my first days of web programming, and it’s become so embedded in my brain that I type it without thinking.

It wasn’t until today, thanks to Rudy Limeback, Steve Lewis, and other folks on evolt’s TheList, that I learned it’s mainly a Microsoft thing and its use is frowned upon in the rest of the community. What a shock! How did that one slip by me for so long? Admittedly I’m pretty ensconced in the world of Microsoft, but I still keep my head up and my eyes open to what’s going on in the world around. And I thought Hungarian Notation was pretty well accepted everywhere. That teaches me a lesson, I guess—pay attention, don’t take programming practices for granted. And it’s probably a good thing I learned that now, before I dive too far into PHP. Otherwise I would have been doing things like $strFileName = $_SERVER[’PHP_SELF’]; and not thought twice about it.

Filed under The Computer Vet Weblog

Comments (2)

Comments RSS - Write Comment

  1. Kalrac says:

    What, you mean that “lpczstrFilename” isn't immediately readable and clear and forces you to instantly understand the code?

    Actually, even Microsoft is moving away from Hungarian Notation. With .NET, they actually discourage its use. About the only remnant lingering is m_memberVar for class member variables, and half the time they'll even leave out the m in MS code.

    Posted July 6, 2003 @ 2:02 am
  2. Kalrac says:

    I dug up the original paper on Hungarian Notation (It's in the MSDN) and found this wonderful example of Hungarian Notation at its finest. Doesn't it help you learn about the code?

    “The following partial example of an actual symbol table routine illustrates the use of the conventions in a “real life” situation. The purpose of this example is not to make any claims about the code itself, but to show how the conventions can help us learn about the code. In fact, some of the names in this routine are standard.

    1 #include “sy.h”
    2 extern int *rgwDic;
    3 extern int bsyMac;
    4 struct SY *PsySz(char sz[])
    6 {
    7 char *pch;
    8 int cch;
    9 struct SY *psy, *PsyCreate();
    10 int *pbsy;
    11 int cwSz;
    12 unsigned wHash=0;
    13 pch=sz;
    14 while (*pch!=0
    15 wHash=(wHash>11+*pch++;
    16 cch=pch-sz;
    17 pbsy=&rgbsyHash[(wHash&077777)%cwHash];
    18 for (; *pbsy!=0; pbsy = &psy->bsyNext)
    19 {
    20 char *szSy;
    21 szSy= (psy=(struct SY*)&rgwDic[*pbsy])->sz;
    22 pch=sz;
    23 while (*pch==*szSy++)
    24 {
    25 if (*pch++==0)
    26 return (psy);
    27 }
    28 }
    29 cwSz=0;
    30 if (cch>=2)
    31 cwSz=(cch-2/sizeof(int)+1;
    32 *pbsy=(int *)(psy=PsyCreate(cwSY+cwSz))-rgwDic;
    33 Zero((int *)psy,cwSY);
    34 bltbyte(sz, psy->sz, cch+1);
    35 return(psy);
    36 }”

    Uh… Yeah. I've been programming since '96, I have a four year degree in Computer Science and almost a year's worth of professional experience, and I don't have the slightest bloody clue what in the hell this is supposed to do.

    Posted July 6, 2003 @ 2:13 am

Write Comment