Home > Articles > Software Development & Management > Agile

  • Print
  • + Share This

Process

Work in an environment that lets you alternate testing and changing your code.

Apply one refactoring, then run the unit tests. Repeat this process until your code expresses its intent clearly, simply, and without duplication. At first, it may feel awkward to run the tests so often, but it will speed you up to do so. (It takes a few seconds to run the tests, but it reassures you that several minutes worth of changes are OK.)

When are we done? When the code

  1. Passes its tests (works)

  2. Communicates everything it needs to communicate

  3. Has no duplication

  4. Has as few classes and methods as possible

These goals are in priority order: if duplication is required to communicate, the code is duplicated. The goals are often compressed to the phrase "once and only once" ("once" to work; "only once" to avoid duplication).

In The Pragmatic Programmer, Dave Thomas and Andy Hunt (2000) discuss a similar but more general rule known as the DRY principle ("Don't Repeat Yourself"): "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.