DRY is one of the most important design principles every engineer should understand for the sake of engineers life(literally)

This article was written as an individual review assignment for PPL CSUI 2021

In this age, software engineer skill of coding and problem solving is just a basic skill that every engineer should have, that’s why every company will doing some coding test for their recruitment test before recruiting a new employee. But, when it comes to software engineering, there is much more skill that engineer should have for the success and scalability of the project. Software engineer skill of design pattern and design principle is a must for every engineer to have.

there are dozen of design patterns that known and also a dozen of the design principles that already known and used by many engineers, but should we remember all of them and use all of them? For me, the answer is no, in my opinion, design pattern and design principle is just a weapon in engineer's arsenals that engineers can use when engineers thought that weapon is the best choice to use for their cases. So the conclusion is, everything already has its own cases, don’t overuse it :)

These two concepts are very important because of their impact to make software engineer works much easier(eventually). By implementing this concept, our project will get much cleaner and easier to maintain. it’s very important to keep your code clean and maintainable so, when you need to scale up your project or adding more features, it’s easy to do that without any worries.

DRY, acronym for Don’t Repeat Yourself, in my opinion, is the easiest and very versatile principle that can be used in many tools and many cases. so it’s useful for us to try to understand it and try to implement this principle. just like the name, Don’t Repeat Yourself, this principle encourages us to think to became much more lazy person, and always think to reuse everything, NOT COPY AND PASTE it. I will give some practical examples from my own project of how I use this principle to make my team work easier and faster and of course, cleaner.

In my project, I have to implement the UI just like I show you in the above picture. as we can see, there are many Widget that most likely the same and if we don’t implement DRY, then we need to create 8 different widgets, well that sound very boring and exhausting :(. So because I’m too lazy to create 8 different widgets, then I implement DRY and just using one reusable widget that I can reuse. I will show you how bad it is to create 8 different similar widgets.

as you can see, this is the example of when I don’t use the DRY principle in my project, in just one dart file, it contains more than 500 lines of code, well, for me it’s very intimidating to read and I’m already exhausted for just imagine to debug from this file :(. let's see the difference when I use the DRY principle.

this code snippet was the reusable widget that I create. with this code snippet, I could minimize the amount of line of code from more than 500 lines of code to just 150 lines of code. well, this is very good news for every engineer because less of lines they should read and debug :D. Maybe it looks easy, but of course, it’s easy if we know how DRY will help us and we also knew well the requirement of our projects.

DRY is just one of a dozen design principle you could find and use, but DRY is one of the design principles that very versatile and could be useful in many cases and in many tools, so it’s worth to know and understand it :)

That’s all for this article, hope it’s will be useful for someone who read it, thanks and stay healthy. Happy Hacking :D

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