clean code by Uncle Bob
- Code rot
- wading code
- different schools of thought, like Jiu Jitsu
Naming
- implicit naming vs explicit naming explicit naming when you have those long names, no need to guess. Implicit naming requires mental mapping. C means count.
- Don't show off your IQ with implicit names, one liners, etc... As a code author, you write for the other devs reading your code.
- Meaningful distinctions Make differences between named things obvious. Bad example
getActiveAccount();
getActiveAccounts();
getActiveAccountInfo();
-
Pronouncable names
-
Searchable names
-
Avoid encoding if you can
- Type encoding (Hungarian notation). Uncle Bob doesn't like I interface prefix.
- Scope encoding.
m_for class members, in Java.globaltmpetc
-
Class/obj - noun, method - verb
-
No culture dependent jokes like
eatMyShorts()instead ofabort() -
One word per concept If
addmeans add to array, then for math addition, use another word like sum -
Contextual grouping street, zip, state, country. When not grouped, you stare at
const stateand wonder wtf? but if grouped in
mailingAddress.statethen it's clear.
address - in "postal context" it's clear. But in other contexts, is it MAC? URL? IP? -
Renaming in old code is OK. If you can improve things, do it.