home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!microsoft!wingnut!russpj
- From: russpj@microsoft.com (Russ Paul-Jones)
- Subject: Re: My view of variable naming conventions (was: Hungarian...)
- Message-ID: <1992Jul30.191531.20810@microsoft.com>
- Date: 30 Jul 92 19:15:31 GMT
- Organization: Microsoft Corporation
- References: <1992Jul27.013310.24591@uwm.edu>
- Followup-To: comp.programming
- Lines: 71
-
- This really isn't a C issue, so I've directed followups to comp.programming.
-
- In article <1992Jul27.013310.24591@uwm.edu> markh@csd4.csd.uwm.edu (Mark William Hopkins) writes:
- >
- >Experience with my own code and other people's code have borne out this
- >assessment time and time again:
- >
- > If you find yourself reverting to Hungarian Notation,
- > then you've violated all the [below], (0) through (5).
- >
-
- I'm not sure what you mean. If you mean that you only need to resort
- to Hungarian when you've already broken the rules, I'll disagree by
- saying that I start with Hungarian in new code. For those rules that
- I agree with, I find Hungarian a good implementation. If you are saying
- that Hungarian itself violates these rules, well:
-
- >I've always followed these rules in naming objects, like variables in C (or
- >Pascal):
- >
- >(0) Declare as close to 0 variables and parameters at any scoping level as
- > possible.
-
- Hungarian neither requires nor encourages extra variables and parameters.
- It does encourage extra typedefs, but you can control this.
-
- >(1) Declare all objects as local as possible, even within a statement block.
-
- Hungarian is a naming convention, not rules on where to declare the objects.
-
- >(2) Use generic names for generic objects, and short, common (and appropriate)
- > natural language words for objects with semantic content.
-
- Hungarian establishes short, common names with semantic content for generic
- objects. They are not natural language words, but I believe it is easier
- to establish short names with semantic content using Hungarian than in
- casting about for appropriate natural language words for objects.
-
- >and these rules:
- >(3) If you have to comment on a variable's use, then you've named it wrong.
- > Rename it.
-
- Using Hungarian, I almost never comment on a variable's use. The point of
- the name is to define its use.
-
- >(4) If you run into numerous name clashes, then you've violated (0) and (1).
- > Eliminate the extraneous fluff.
-
- Properly used Hungarian will in fact show up violations of (0) and (1), as
- you are supposed to use identical names for objects being used in
- identical ways.
-
- >(5) If you find yourself getting confused about types, then you're not
- > thinking straight about what your program is supposed to be doing.
- > Go back to the drawing board.
- >
-
- Again, Hungarian is not about types, it is about usage. Is this rule
- saying that random variable names in code are OK as long as the programmer
- is thinking straight about what the program is supposed to be doing?
-
-
- I still have a 40K document describing a dialect of Hungarian close to
- what I use. This dialect is distinct from that used in the Windows SDK
- documentation. It is available on e-mail request. Most of the discussion
- on Hungarian that I've seen has nothing to do with the naming convention
- I use.
-
- -Russ Paul-Jones
- russpj@microsoft.com
- As far as I know, Microsoft does not endorse Hungarian notation.
-