Nomenclature
General Principles
Names should reveal the intention/purpose of the entity. So, choose good and meaningful names.
Descriptive
Avoid abbreviations
genYmdHms() -> generateTimestamp()Avoid generic words, e.g:
Manager,Processor,Data,Info.Pronounceable.
DataRcrd123 -> CustomerWhen using an acronym, if it consists of two letters, capitalize it. If more, treat it as a word.
IOStream, HttpInputStream, XmlFormatter, sendOtp()Add prefix
hasoristo variable/method with Boolean type/returnval isPosted : Boolean = false fun hasAttachedDocuments() : Boolean { .. }Avoid encoding, hungarian notation, and member prefixes
Explain yourself in code
invoice != null && invoice.status == Status.REJECTED -> isInvoiceRejectedSearchable
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/getWrite 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
constorvalproperties with no customgetfunction
Last updated
Was this helpful?