Re: How to name variables in a program?



SerGioGio wrote:

> Having a strong convention for naming your variables in your program is an
> important issue often overlooked.

Many shops take that ideal reasonably seriously. They often couch it in a
larger ideal: The code should appear as if written by only one, very
intelligent individual. Put another way, you should not be able to tell who
wrote what by looking at its structure, style, format, or naming
conventions.

Get that by collaborating closely on each other's code.

> Can anyone point me to a good source on the web dealing with this issue?

Google for "intention revealing selector" for one topic. And here's a
summary of the rest:

- pronounce identifiers and statements out loud, to ensure they make sense
- methods are verb phrases
- classes are generic nouns
- objects are specific nouns
- use the same name for the same thing, spelled the same
- don't use l, i, O, etc. for local variables.
- Use spikey things like x, k, j, q, etc.
- don't use long names for local variables
- don't use short names for global things
- prefix strings with s or str
- prefix objects or references with a
- prefix pointers with p
- don't prefix anything else - rely on clarity
- use CapitalizedNames for important things
- use camelCase for methods

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand


.



Relevant Pages

  • Re: Questions about components naming convention
    ... "Vince" a écrit dans le message de ... > I'm writing a naming convention... ... Do you see an advantage to use a prefix like "a" before ... I saw that VCL already use a similar convention on some parameters "AOwner: ...
    (borland.public.delphi.language.objectpascal)
  • Re: silent semantic changes with reiser4
    ... was just a style convention for metafiles, ... prefix with a subdirectory ... > that one could ls it to see all the builtins supported by a given ... applications) don't trip over this stuff, it is a moby nightmare security ...
    (Linux-Kernel)
  • .NET Naming Guidelines (C#)
    ... The recommendations ... Member Variable Prefix: Most of the people still use (and like the ... Use "m" as it also matches the convention generally followed ... Hungarian Notation / Type Prefix: This is now regarded as a bad ...
    (microsoft.public.dotnet.general)
  • Re: Hungarion Notation is out but..
    ... feeling with respect to HN and at this point feel its ok to prefix the ... I'd like to give some input on the original question. ... > than another way to avoid this naming conflict) is to imbed the logic ... So by following this naming standard you can differentiate ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to name variables in a program?
    ... The Java naming convention is pretty good on this. ... the symbol is with the first letter capitalized, ... I would also *HIGHLY* warn you against the hungarian notation. ...
    (comp.programming)