Re: How to name variables in a program?
- From: August Karlstrom <fusionfive@xxxxxxxxx>
- Date: Mon, 30 May 2005 03:21:05 GMT
Phlip wrote:
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
Personally i think e.g.
name := person.Name()
makes more sense than
name := person.GetName()
I use "get" only when naming functions/methods that take an out parameter (changes the value of its parameter), e.g. in C:
int n; ... get_some_value(&n);
More specifically, following to the command/query principle: Use a noun describing the returned value for queries (methods returning a value with no side effects) and verb phrases for commands (methods with side effects that doesn't return a value).
- 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.
You probably mean - 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
This is standard in Java. Other languages has other conventions. .
- Follow-Ups:
- Re: How to name variables in a program?
- From: Phlip
- Re: How to name variables in a program?
- References:
- How to name variables in a program?
- From: SerGioGio
- Re: How to name variables in a program?
- From: Phlip
- How to name variables in a program?
- Prev by Date: Re: How to name variables in a program?
- Next by Date: Re: Suggestions for double-hashing scheme
- Previous by thread: Re: How to name variables in a program?
- Next by thread: Re: How to name variables in a program?
- Index(es):