Disclaimers
- This is not original content.
- The code I produce often fails to live up to the standards I strive for.
Readability
- Practice aimed at reducing complexity for the reader.
- Practices that you can apply as you are coding.
Why is it important
- Aids maintenance.
- If you can not understand it you can not safely change it.
- Move fast and not break thing is a better model.
Appeals to authority
- Linus Torvalds ( Linux, Git ).
- Theo de Raadt ( Open BSD ).
- Martin Thompson ( Betfair/LMAX ).
What the talk is not about
- SOLID, Coupling/Cohesion, architecture, Paradigms
- Formatting.
- Tools or Organisation independent approaches.
Underpinnings
- Chunking theory.
- Short term memory has seven slots.
Techniques
- Single level of abstraction principle.
- Cyclomatic complexity.
- Remain true to the model.
Single level of abstraction principle.
- Code in a method should all be at the same level of abstraction.
- Domains or Environment.
- Worker or Manager.
- Functional or Imperative.
Cyclomatic complexity
- Is a measure of how complex a method is.
- Start at one.
- Add one to the cost for every branch ( selection, iteration, etc ).
- Add one to the cost for every conditional operation ( &&, !! ).
- If you get past five it is too complex.
- Do this manually as you write/modify a method.
Remain true to the model
- All code should be written to some mental model.
- Affords consistency.
- Can be documented so that new developer can maintain that consistency.