Meaningful Names
Use Intention-Revealing Names
Choosing a good name takes time, but saves more time
A name should tell
Change a name when finds a better one
Why it exists
What it does
How it is used
If a name needs a comment, then the name does't reveal its intent
Avoid desinformation
Avoid false clues that obscure the meaning of the code
Spelling similar concepts similarly is information
Using inconsistent spellings is desinformation
Make meaningful distinctions
Using number series is non informative
Noise words are another meaningless distinction
Noise words are redundant
Use pronounceable names
Use searchable names
single-letter names can only be used as local variables inside short methos
The length of a name should correspond to the size of its scope
If a variable or constant migth be seen or used in multiple places, it is imperative to give it a search-friendly name
Avoid encoding
Variables with its type or collections
Ex: phoneString
Avoid mental mapping
Variable name that the reader must mentally map to the actual concept
Class names
Classes and objects should have noun or noun phrase names
Should't be a verb
Method names
Should have verb or verb phrase names
Accessors, mutators and predicates
get, set and is
Pick one word per concept
When constructors are overloaded, use static factory methods with names that describes the arguments
Consider enforcing their use by making the corresponding constructor private
One word for one abstract concept
Don't pun
Avoid using the same word for two abstract concepts
Use solution domain names
Terms that programmers will know
Problem domain names
When can't use solution domain names
Add meaningful context
Isolated variables can be added a prefix context
It's better to create a class
Don't add gratuitous context
Shorter names are better than longer ones
Final words
Harder thing about choosing good names is that it requires good descriptive skills and a shared cultural background