Principles are guiding rules to be more successful. You need to constantly keep these in mind and have them serve as a guardrail to keep you focused towards writing good, and clean software.
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”– Martin Fowler
Keep it simple, stupid (KISS), you aren’t gonna need it (YAGNI), and don’t repeat yourself (DRY) are some of the most powerful code design principles. Those are the three principles every developer should heed, as they are about clean code.
In this article we are going to understand what each of them mean.
KISS is an acronym for Keep It Simple, Stupid. This principle says about to make your logic as simple as possible, and oftentimes as un-optimized as possible. You should avoid unnecessary complexity. A simple code it’s easier to maintain and easier to understand.
Aim for extreme simplicity and write minimal amount of code. And remember my wise words:
It is not about how many lines of code you write, it is about how few.– Lockheed Martin
Advantages of the KISS principle
- Users don’t want to waste time. They expect a frictionless experience with straightforward, intuitive user flows, jargon-free naming, and quick results.
- A simpler software structure makes testing, including also automated testing, easier and more effective.
- Reduced codebase complexity makes maintenance and onboarding of new team members mid-project easier and faster.
YAGNI stands for You Ain’t Gonna Need It. It’s a principle from software development methodology of Extreme Programming (XP). This principle says that you should not create features that it’s not really necessary.
It’s similar to the KISS principle, once that both of them aim for a simpler solution. The difference between them it’s that YAGNI focus on removing unnecessary functionality and logic, and KISS focus on the complexity.
Ron Jeffries, one of the co-founders of the XP, once said:
Always implement things when you actually need them, never when you just foresee that you need them.– Ron Jeffries (co-founders of the XP)
The primary benefit of using YAGNI is a more cost-optimized product development process due to:
- Better developer performance: The team focuses on delivering the current requirements effectively. They don’t spend time and effort on guesses.
- More flexible codebase: You don’t have to find ways to use suboptimal solutions that you had already developed before you had the full picture.
DRY stands for Don’t Repeat Yourself. In the book ‘The Pragmatic Programmer’, we can see this definition for DRY:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.– The Pragmatic Programmer
This means that you should not have duplicated code. It’s easier to maintain a code that is only in one place, because if you need to change something in the code, you just need to change in one place. Besides that, if you have the same code in two or more places, the chance of this code become different during the time is high, and when this happens it will become an easy way to introduce bugs in your system. Duplicated code also makes the code more complex and unnecessarily larger.
You also should not write ambiguous code. Your classes, your variables, your functions, they should have a specific name, and their name must match their responsibility. If you have a function, you should know what the function does by just reading its name, without being needed to read the code inside of it.
How does the DRY principle benefit products?
The DRY principle ensures that any modification of a single element of a system does not require a change in other, logically unrelated elements. So it’s an effective way of streamlining the development process. In addition, elements that are logically related change predictably and uniformly, which keeps them in sync.
As you can see, in the end, the benefits of KISS, YAGNI, and DRY are strongly tied to the overall product’s success and the organization’s KPIs. Therefore, product owners, project managers, and C-level executives who understand the potential of these design principles, and have their teams apply them in every iteration, have higher chances of market success.