The Seven Code Virtues – The Code
Agile
in a Flash by Jeff Langr and Tim Ottinger (card #42)
> Working, as opposed to
incomplete
> Unique, as opposed to
duplicated
> Simple, as opposed to
complicated
> Clear, as opposed to
puzzling
> Easy, as opposed to
difficult
> Developed, as opposed to
primitive
> Brief, as opposed to chatty
--
Working,
as opposed to incomplete. A program that works is superior to one that might
work later. TDD requires code to work early and often.
Unique,
as opposed to duplicated. Many regression errors are the result of
improvements to only one version of copied code. Eliminate duplication in TDD’s
refactoring step.
Simple,
as opposed to complicated. Simple code hides fewer bugs and tends to optimize
well.
Clear,
as opposed to puzzling. Code misunderstandings generate errors. Use Card
43, Really Meaningful Names, and simple structures to make such errors
unlikely.
Easy,
as opposed to difficult. Structure and organize code so that it is easy to
use. Don’t hesitate to add convenience methods and classes.
Developed,
as opposed to primitive. Prefer the clarification and encapsulation of
abstract data types to built-in variable types. Primitive obsession muddles the
code and can create maintenance nightmares.
Brief,
as opposed to chatty.
Code should be brief but never cryptic. All other virtues still observed, less
code is always better than more.
"Complicated code is
infinitely more difficult to maintain and debug than simple code.”
No comments:
Post a Comment