Neatness is achieved by falling into the design

Four rules of simple design:

  • Run all tests
  • Do not repeat
  • Expresses the intent of the programmer
  • Minimize the methods and number of classes
  • The above rules are listed in order of importance

1. Run all tests

Design must produce a system that works as expected. This is the first factor. It doesn’t matter if the system has a good design or not, if it doesn’t work as expected, it won’t work.

A system that is fully tested and consistently passes all tests is a testable system. It may seem obvious, but it matters. A system that is not testable is also not verifiable. Unverifiable systems should never be deployed.

2. Simple Design Rule 2-4: Refactor

Once the code is correct through testing, it’s time to focus on the design of the code. Adding code, while keeping the code correct, should focus on whether the design regresses, and if so, clean it up.

Everything you know about good software design can be applied during the refactoring process. Improve cohesion, reduce coupling, split the focus, modularize the systemic focus, reduce the size of functions and classes, choose better names, and so on. These are also the last three principles of simple design: eliminate duplication, ensure expressiveness, and minimize the number of classes and methods.

3. Do not repeat

I wrote in my previous reading notes that REPETITION is my enemy

As soon as something is repeated three or more times, it’s time to take the logic out of that piece and reuse it.

4. Expressive

It’s easy for us to understand the code we write, because when we write it, we’re deeply involved in the problem we’re trying to solve. Other maintainers of the code are not as deep and have difficulty understanding the code. Good code should therefore clearly express the intent of its author.

What does good code look like: good naming, keeping functions and classes short, good unit testing, and so on

However, the most important way to be expressive is to try. Too often, we write code that works and move on to the next problem, without putting enough effort into tweaking the code to make it easier for later generations to read.