The Ockham's Razor, Clean Code and How to use it in the development process?
In this text, I will discuss Ockham's Razor and draw a parallel between its concept, our daily code development process and Clean Code.
What's the Ockham's razor?
Put in a simple way, Ockham's razor is the problem-solving principle that recommends searching for explanations constructed with the smallest possible set of elements. It is also known as the principle of parsimony or the law of parsimony.
That is the idea of a razor is to cut (that's what the razors do) the complex explanation about something, and start to look at the smallest (simplest) explanation at first avoinding looking for the excessfuly complex solutions for a problem.
This idea was attributed to William of Ockham, a Franciscan Friar, philosopher, and theologian from the 14th century. Although he didn't coin the term, the way that he used the method inspired other philosophers to develop the idea and they used Ockham's to name it.
We can also use this principle to debunk conspiracy theories. For example, a more complex explanation for the construction of the pyramids is that aliens built them. This would require us to accept that aliens visited Earth, taught humans how to build the pyramids, and then never returned. A simpler and more plausible explanation is that the ancient Egyptians constructed them using their own ingenuity and resources. This was also discussed on the Season 1, Ep. 2 of the Pantheon Series.
KISS Principle, Ockham and Clean Code
The KISS principle, which stands for “Keep It Simple, Stupid”, emphasizes the importance of simplicity in software design and development. The goal is to prioritize straightforward solutions over complex ones. By keeping our code simple, we can enhance comprehensibility, usability, and maintainability. The KISS principle applies not only to code but also to various aspects of software development, including architecture and user interface design. See 2 The Principles of Clean Code: DRY, KISS, and YAGNI
The KISS principle, along with others like DRY (Don’t Repeat Yourself) and YAGNI (You Ain’t Gonna Need It), are fundamental concepts for writing clean code. When we examine the KISS principle, we can see some similarities with Ockham's Razor, particularly in its emphasis on simplicity.
In Brazil, there's a saying: "Matar formiga com uma bala de canhão," which translates to "Kill an ant with a cannonball." It serves as a reminder that when solving or creating something, it’s better to start with the smallest and simplest solution.
Similarly, when debugging or investigating a problem, it’s crucial to begin with the most straightforward explanation. For example, if a customer reports an issue with their software, the first step is to check the documentation to ensure they're using the software correctly. Next, you might look for similar documented bugs and try to reproduce the issue. Only after confirming it's a bug should you proceed to investigate and fix it.
That’s it for today! I hope this text provides valuable insights. If you have a different perspective or any concerns about the topic, don’t hesitate to reach out—I’d love to hear your thoughts.
References
- https://en.wikipedia.org/wiki/Occam%27s_razor
- https://medium.com/@curiousraj/the-principles-of-clean-code-dry-kiss-and-yagni-f973aa95fc4d
Disclaimer: I have no formal education in philosophy or psychology. These are just my personal thoughts and reflections! Additionally, the views expressed here are entirely my own and do not represent the ideas or opinions of the company I work for.