(2022-01-15) Jeffries Strawberries3 Simple Design

Ron Jeffries: Strawberries 3: Simple Design. Among the eminent Kent Beck’s many contributions are his four rules of simple design. My preferred formulation is this one:

The code is simple enough when, in priority order:
It passes all the tests;
It contains no duplication;
It expresses all our design ideas about the code;
It minimizes programming entities.

Passes All the Tests
If the code doesn’t work, there is no point simplifying it. If we don’t know that it works, we really need to determine that before “improving” it

Contains No Duplication
At its surface, this rule prevents copy-pasta

Personally, I often find that it’s only in looking at the code during duplication removal, and after it, that I really see what my own idea was.

Expresses All Our Design Ideas
Most of us have the experience of looking at some big block of code and suddenly understanding a chunk of it.

When we have that experience, we owe it to the world to extract that chunk of code into a function or subroutine or method and give it a name that expresses what it’s doing

Minimizes Programming Entities
The other rules being satisfied, we’d like to have as few functions, classes, methods, modules, files, variables, trumtookas, whatever elements there are in our program.

Duplication Before Expression?

if these two rules are ever in conflict, then there are two or more things in the code that look like duplication, but there is some design truth that makes that breakout “correct”. That is: If removal of duplication and expressing ideas are ever really in conflict, choose to express the ideas.

why then, do I put the duplication rule ahead? I do it because it is such a powerful tool: Duplication is generally very easy to spot.


Edited:    |       |    Search Twitter for discussion