Programming Principles
TL;DR
Maintaining clean code & making realistic dev time estimates.
-
- especially subprograms:
- for independently decomposable subproblems: separately implement & test before combining
-
code may be duplicated ONCE
- anything more warrants abstraction into a separate reusable procedure
- alternative is bad design, bad habit, hard to maintain
- “small” last-mile problems are often hard
-
over-optimisation: never sacrifice clarity for efficiency
- profile to find the small bottlenecks of code (likely ~10%) to optimise
-
use naming conventions for identifiers (variables, types, functions)
- easier to read & understand (and thus maintain) code
- sane style (e.g. no extra-long names nor unclear abbrev.)
- holy wars over what style to pick are not important; just pick one consistently
- tips:
- descriptive of contents
- or common lang-specific practice (e.g.
i, j, k
for indices) - subprogram names: use verb phrases; i.e. ONE – see rule (1) above – activity description
- variable names: nouns (things) or adjectives (attributes)
- difficulty finding a name indicates code needs refactoring, better design, clarification of purpose of subprograms/variables