principleModeratepending
Naming things well -- the hardest problem in programming
Viewed 0 times
naming conventionsdescriptive namesubiquitous languagereadabilityintent
Problem
Bad names force readers to look up definitions, trace code paths, and build mental models that the name should have provided. Variables named data, result, temp, or x carry no information.
Solution
Good names are: (1) Descriptive: activeUserCount not n. (2) Unambiguous: fetchUserProfile not getData. (3) Consistent: if you use get for sync reads and fetch for async, do so everywhere. (4) Appropriately scoped: loop variables can be short (i, item), module-level should be descriptive. (5) Domain-specific: use the ubiquitous language from your domain. Avoid: abbreviations (usr, mgr, impl), generic names (handler, processor, manager, utils), Hungarian notation.
Why
Code is read far more often than written. A good name communicates intent instantly. A bad name forces the reader to read the implementation to understand the abstraction.
Revisions (0)
No revisions yet.