Design: What is simplicity?

Should it be global or local?

Image for post
Image for post
Each of those 25 microns-wide facets (ommatidium) of a noctuid moth’s eye is pretty simple, but their composition performs a very complex vision feature [Dartmouth Electron Microscope Facility/Dartmouth College]

The goals of simplicity

Maybe asking the question of the benefits of simplicity can help to grasp its definition. Why are we looking for simplicity? Obviously to make our work easier. We want:

  1. maintainability: to be able to understand (readability) and change quickly so that you can debug/fix or evolve.
  • by speeding up you may be thinking “too fast” and have a higher risk of introducing bugs ;
  • we read code more frequently than we write it (often once) so you should not give more importance to something you do only 20% of the time.

How to make things simple?

Global simplicity is only reachable for simple apps. Most applications provide value because they handle complex problems, so we have to find out how to design maintainable solutions to complex problems.

When to split?

What is the proper granularity between too complex and too simple? A couple of principles can help deciding:

  • the cohesion of your class, that is, the propensity of a class’s method to use most of the class’ attributes, is also a big clue about the need for split. If some methods are only using a sub-set of the class’ attributes, they probably should better fit in a separate class.

Splitting cost

Some people might be concerned by the idea that splitting adds layers and that communications between those layers might be costly in terms of:

  • performance, especially if the layers are remote, like in micro-services architectures.

Do you want your tools organized into toolboxes with many small drawers each containing well-defined and well-labeled components? Or do you want a few drawers that you just toss everything into?

Conclusion

Only simple programs can achieve global simplicity. The majority of others can and should only target local simplicity, that is, simplicity of the code part you’re maintaining at a given time. This can only be achieved by proper code split in simple abstractions according to the SRP principle.

Software engineer for three decades, I would like to share my memory.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store