I read the relatively short book Understanding the 4 Rules of Simple Design by Corey Haines. He uses examples to explain the rules from experiences from the many Code Retreats he has been to. These rules were originally described by Kent Beck in their book “Extreme Programming Explained” after it was already discussed on Ward Cunninham’s Wiki.
So what are these rules? Well they are better thought of as guidelines.
- Tests pass
- Expresses intent
- No duplication
- Small
I found it interesting that he used Conway’s Game of Life as the programming example. It’s about simple rules and the emergent behaviors that arise which goes back to chaos theory. I wonder if he’s trying to imply that there is an emergent design that arises from these four rules (also see emergent design in agile software development).
I came across “Tiny Decisions and Emergent Design” interview with Kent Beck which was relevant to the book and emergence (about 16 minutes in). He stresses that context matters as well as values and principles (like shortening feedback loops, absorbing more feedback and responding in those cycles, see Chapter 4 and 5 of Extreme Programming Explained) but that people want to have simple answers and want the rules to be prescriptive so that they don’t have to think and are absolved of their own decisions. He also questions our models of quality software versus reality of it:
“We all have this simplistic model of [software] quality in our heads, everything will be easy to read and beautifully document. And if you look over and over again, software doesn’t look like that. Maybe the problem isn’t with the software, maybe the problem is the model of quality in your head and you need to take a step back. What model of quality would predict software that looks exactly like this?
(22 min in)
This all also get’s me thinking about how code is created in Wikimedia and how the structure of Wikipedia is an example of a complex adaptive system, “By managing behavior, and not only mere content, Wikipedia uses simple rules to produce a complex, evolving knowledge base which has largely replaced older sources in popular use.”
But back to those four guidelines. I do seem to run up against them from time to time and I do agree that they are helpful when writing code. I also understand where my mentor is coming from when I’m trying to write more than is needed or use variable names that could be worded better. I’m certainly going to keep these guidelines in mind but more importantly stay alert and mindful of context!