Nomenclature
General Principles
Names should reveal the intention/purpose of the entity. So, choose good and meaningful names.
Descriptive
Avoid abbreviations
Avoid generic words, e.g:
Manager
,Processor
,Data
,Info
.Pronounceable.
When using an acronym, if it consists of two letters, capitalize it. If more, treat it as a word.
Add prefix
has
oris
to variable/method with Boolean type/returnAvoid encoding, hungarian notation, and member prefixes
Explain yourself in code
Searchable
Classes & Objects
A descriptive class names are usually a noun or a noun phrase saying what the class is:
DeliveryOrder
,UserPreference
.Avoid meaningless name
Write in PascalCase
Functions / Methods
A descriptive method names are usually a verb or a verb phrase saying what the method does:
createInvoice()
,save()
Self explanation
Pick one word per concept, e.g:
fetch
/retrieve
/get
Write in camelCase
Variables / Properties
Having variable type as part of name
Use plural names for arrays / collections
Write in camelCase, for variables that hold objects with behaviour or mutable data
Write in SCREAMING_SNAKE_CASE, for
const
orval
properties with no customget
function
Last updated
Was this helpful?