DEV Community

Cover image for Clean Code Essentials: YAGNI, KISS, DRY

Clean Code Essentials: YAGNI, KISS, DRY

Ravin Rau on December 17, 2024

In the world of software engineering, where clean code and efficient design patterns reign supreme, three principles stand out as guiding lights: Y...
Collapse
 
bednic profile image
Tomas Benedikt

YAGNI does not make space for innovation and improvements. It seems like business focused. Which means only necessary things, defined outside of team will be realized. There should be always encouragement to do small cheap perks which improves product.
KISS principle works fine and by my observation is the most important. It helps with onboarding and should help with cognitive complexity.
DRY principle is very komplex and very often is in collision with KISS. Implement DRY the right way is hard and you need years of experience in software architecture, to recognize patterns and propose right abstraction. Sometimes two components which seems same are not same in core purpose and you will end up in same fuck ups like React framework.
So conclusion is, YAGNI should not stop programmers from doing nice cheap improvements in code. DRY is hard, even if it doesn't seems like that. KISS has always preference over DRY.

Collapse
 
juniourrau profile image
Ravin Rau

This is a thoughtful perspective on these principles! I completely agree that YAGNI can sometimes feel too business-focused and potentially stifle innovation if taken to the extreme. Encouraging small, low-cost improvements that enhance the product and codebase is essential for fostering creativity and maintaining developer morale.

Your observation about KISS being the most impactful resonates strongly. Keeping things simple not only aids onboarding but also reduces cognitive load, which is vital for maintaining productivity in the long run.

Regarding DRY, you're spot on about its complexity. Striking the right balance between abstraction and simplicity requires deep architectural insight, and as you mentioned, it can easily conflict with KISS. The React example is a great illustration of how over-generalizing can lead to unintended issues.

Ultimately, I agree with your conclusion: YAGNI should not discourage thoughtful improvements, and KISS should take precedence over DRY when conflicts arise. This balanced approach ensures practical, maintainable, and innovative development.

Collapse
 
codemouse92 profile image
Jason C. McDonald

Instead of YAGNI, I think about where we might want to take the product in the future, and then work backwards to ensure I'm not blocking any future development work. It's the idea that, you may not need that feature right this moment, but if you can make some simple design decisions now that make it possible, do it.

DRY is good to a point, but I've seen it get out of hands many times, producing code that is so abstracted it's virtually unmaintainable. The GCC compiler source (at least as of a few years ago) is a great example of overly DRY code.

Thread Thread
 
juniourrau profile image
Ravin Rau

Valid viewpoint, thank you very much for sharing this. Too much of something can sometimes be a bad thing. The right way is always to find that balance that enables you to be productive and efficient. At the end of the day, time is the most valuable thing, and being productive ensures that you can give the most output.

Collapse
 
lincpa profile image
Lin Pengcheng • Edited
Keep it Simple and Unified. 
Only simple can unity, 
only unity can be truly simple.

Traditional IT theory (OO, FP and hardware architecture, etc.) 
are pseudoscience. they belong to what physicist 
Wolfgang Pauli said "Not Even Wrong".

It is the perfect theory if a theory is based on mathematics 
and meets the five basic principles of "Simplicity, Unity, Order, 
Symmetry and Definiteness" in science, industry and aesthetics.  

Computer science is essentially a management science, 
and vice versa.

Software and hardware are factories that manufacture data, 
so they have the same "warehouse/workshop model" and 
management methods as the manufacturing industry.

        ---- Lin Pengcheng

The chief forms of beauty are order and symmetry and 
definiteness, which the mathematical sciences 
demonstrate in a special degree.
       ---- Aristotle, "Metaphysica"
Enter fullscreen mode Exit fullscreen mode

My programming aesthetic standards are derived from the basic principles of science. Newton, Einstein, Heisenberg, Aristotle and other major scientists hold this view.

The aesthetics of non-art subjects are often complicated and mysterious, making it difficult to understand and learn.

The pure function pipeline data flow provides a simple, clear, scientific and operable demonstration.

Simplicity and Unity are the two guiding principles of scientific research and industrial production.

  • Unification of theories is the long-standing goal of the natural sciences; and modern physics offers a spectacular paradigm of its achievement. It can be found from the knowledge of various disciplines: the more universally applicable a unified theory, the simpler it is, and the more basic it is, the greater it is.

  • The more simple and unified things, the more suitable for large-scale industrial production.

  • Only simple can unity, only unity can be truly simple.

In the IT field, only two systems fully comply with these 5 programming aesthetics:

  • Binary system

The biggest advantage is that it makes the calculations reach the ultimate simplicity and unity, so digital logic circuits are produced, and then the large-scale industrial production methods of computer hardware are produced.

  • The pure function pipeline data flow with principle-based warehouse/workshop model

From:

Collapse
 
juniourrau profile image
Ravin Rau

Thanks for sharing this perspective view. While I was reading this, the first thing that popped into my mind was the concept of the first principle. Start with a simple understanding/concept and slowly build from there. As you build, you optimize and aim to make things efficient. Continue and repeat the cycle.

Thanks for sharing your thoughts. ✨

Collapse
 
chad_fraser_757fa256b86dc profile image
Chad Fraser

"YAGNI, KISS, and DRY truly are the cornerstones of effective software development! 🌟 Adopting these principles not only simplifies the coding process but also ensures scalability and maintainability. A great reminder for both new and experienced developers to keep things clean and efficient! 💻✨"

Collapse
 
juniourrau profile image
Ravin Rau

Thank you very much @chad_fraser_757fa256b86dc

Collapse
 
rinidh profile image
Dhokia Rinidh

Excellent article bro. Complimenting on the YAGNI principle, I also think that out of many thousands of ideas/features we (in present day) may guess and add to our software, only one may hardly be accepted by users in the future. It's very hard to forecast the dynamic future. I guess that's why we should stick to current demands... YAGNI says it well 😉

Collapse
 
juniourrau profile image
Ravin Rau

Thank you very much @rinidhdhokia. You’re absolutely right! Businesses constantly adapt to meet the changing needs of their customers. Predicting customer preferences can be tricky, so it’s often safer to stick to what they’re already asking for. But that doesn’t mean we can’t innovate and find new ways to serve them better in the future!

Collapse
 
ifyour profile image
Willard Wong

Great article, it would be nice if each development principle was accompanied by practical examples! Thanks for sharing!

Collapse
 
juniourrau profile image
Ravin Rau

Thank you very much @ifyour. Sure I would dive deeper into the practical examples when I am focusing specifically on each of the principles in separate articles. This article covers more on the concept and understanding of the principles.

Collapse
 
newcoder789 profile image
Aryan Dixit

Nice small read🙏

Collapse
 
juniourrau profile image
Ravin Rau

Thank you very much @newcoder789 😁

Collapse
 
juliomoreyra profile image
JulioMoreyra

Clear and simple! Great

Collapse
 
juniourrau profile image
Ravin Rau

Thank you very much @juliomoreyra 😄

Collapse
 
robertolabarcab profile image
Roberto La Barca B.

Excelente artículo y que cumple con los 3 principios. Muchas gracias.

Collapse
 
juniourrau profile image
Ravin Rau

Muchas gracias por tus amables palabras! Me alegra saber que el artículo cumplió con tus expectativas y los principios. Tu comentario es muy valioso y motivador. 😊

Collapse
 
soleng profile image
na.perruchot

If only...

Collapse
 
juniourrau profile image
Ravin Rau

If only ?

Collapse
 
xmanhugo profile image
xmanhugo

Thanks for sharing, easy to understand

Collapse
 
juniourrau profile image
Ravin Rau

Thank you very much @xmanhugo. 😁