home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!asuvax!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.lang.c
- Subject: Re: My view of variable naming conventions (was: Hungarian...)
- Message-ID: <1992Jul27.055903.24627@organpipe.uug.arizona.edu>
- Date: 27 Jul 92 05:59:03 GMT
- References: <1992Jul27.013310.24591@uwm.edu>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 44
- In-Reply-To: markh@csd4.csd.uwm.edu (Mark William Hopkins)
-
- In article <1992Jul27.013310.24591@uwm.edu>, markh@csd4 (Mark William Hopkins) writes:
- >(0) Declare as close to 0 variables and parameters at any scoping level as
- > possible.
- >(1) Declare all objects as local as possible, even within a statement block.
-
- Absolutely. There's even a name for this: "encapsulation". To get more
- practical: use structs to group related variables, even if makes the actual
- code a bit longer. Ultimately, you'll find it makes maintenence easier when
- related variables are related by a physical structure in the code (as opposed
- to use and unreliable or nonexistant documentation).
-
- >(2) Use generic names for generic objects, and short, common (and appropriate)
- > natural language words for objects with semantic content.
-
- Yes. The length of a variable name should be proportional to the acreage
- of code its scope occupies. 1 letter for a 3-line index counter, and something
- rather longer for something global to the whole program.
-
- >(3) If you have to comment on a variable's use, then you've named it wrong.
- > Rename it.
-
- Yah. A bit of care in naming global identifiers and functions goes a long way.
-
- >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 above, (0) through (5).
-
- Programming in the large is as much about managing complexity as it is about
- solving the problem at hand. Any competant programmer can solve all the
- problems that comprise a large program *in isolation*. And the key to
- managing complexity lies in careful use of encapsulation and abstraction.
-
- If you're having problems remembering the type of a variable, you're
- probably better off rethinking you're program's abstractions, rather
- than adopting some bizarre naming convention that's harder to remember
- how to use than it is to remember the types of your variables
-
- --
- You unlock this door with the key of imagination. Beyond it is another
- dimension: a dimension if sound, a dimension of sight, a dimension of mind.
- You're moving into a land of both shadow and substance, of things and ideas.
- You've just crossed over into... the Twilight Zone.
-