from the book Clean Code by Robert Martin
Use Intention Revealing Name
Name variables and function that will answer the question why it exist.
- Do not use “accountList” if account is not stored in a list
- Lowercase “L” and uppercase “o” is an awful example of disinformation
Make Meaningful Names
- a1 and a2 are non informative variables. there is no clue of the authors intention.
- If you have product class, using productInfo and productData are only noise words. info and data are noise.
- Datatype should not appear in variable name like NameString and CustomerObject class, name and customer is enough
Use Searchable Names
Use searchable names, single letter is NOT an advisable name since single letter can have many instance in a file, it will be hard for you to search.
Before, compilers does not check type, that’s why programmers used to add type in variable name like strName.
Prefix is not needed since it is advised that classes and function short be small enough that you don’t need it.
Should be a noun or a noun phrase, NOT a verb
- Should be verb or verb phrase like postPayment, deletePage or save
- Accessors, mutators, and predicates should be named by their value with prefix get, set, and is like getName, setName, isActive.
Don’t Be Cute
Choose clarity over entertainment/humor
e.g: holyHandGrenade when it should be deleteItems
Pick One Word per Concept
- fetch, retrieve, get
- DriverManager and protocolController, one must be choose from this.