The Simplest Code

Beck describes the simplest code this way, in priority order:

Runs all the tests.

Contains no duplication.

Expresses all the ideas you want to express.

Minimizes number of classes and methods.

(Sometimes he reverses numbers 2 and 3. Interesting thought problem.)

When you are considering YAGNI (You Arent Gonna Need It) and DTSTTCPW (Do The Simplest Thing That Could Possibly Work), you must consider these rules. Generating The Simplest Code is not complete unless you have refactored according to the rules above.

Nearly every objection and concern about YAGNI and DTSTTCPW is about leaving cruft in the code. The Simplest Code says you must not do that. Defense rests.


>> 4. Minimizes number of classes and methods.

One class with one method? Hmm. It would be very hard to do that, without violating rules 1. and 2. in anything but the simplest case.

How do you define what is minimal?



See original on c2.com