In this article, I am going to explore software design principles and their benefits, why design principles are useful for us, and how to implement them in our daily programming. We will explore the DRY and KISS software design principles.
The DRY Principle – Don’t Repeat Yourself
DRY stands for "Don’t Repeat Yourself," a basic principle of software development aimed to reduce the repetition of information. The DRY principle is stated as, “Every piece of knowledge or logic must have a single, unambiguous, representation within a system."
Violations of DRY“We enjoy typing” (or, “Wasting everyone’s time."): "We enjoy typing," means writing the same code or logic again and again. It will be difficult to manage the code and if the logic changes then we have to make changes in all the places where we have written the code, thereby wasting everyone's time.
How to Achieve DRYTo avoid violating the DRY principle, divide your system into pieces. Divide your code and logic into smaller reusable units and use that code by calling it where you want. Don’t write lengthy methods, but divide logic and try to use the existing piece in your method.
DRY BenefitsLess code is good, it saves time and effort, is easy to maintain, and also reduces the chances of bugs.
One good example of the DRY principle is the helper class in enterprise libraries, in which every piece of code is unique in the libraries and helper classes.
KISS - Keep It Simple, Stupid
KISS principle keeps the code simple, clear, and easy to understand. Programming languages are for humans to understand, so keep coding simple and straight, to be understood by human beings. Keep your methods small; each method should never be more than 40-50 lines.
Each method should only solve one small problem, not many use cases. If you have a lot of conditions in the method, break these out into smaller methods. It will not only be easier to read and maintain but also can find bugs a lot faster.
Violations of KISSWe have all experienced situations in which we had work to do in the project and found some messy code. "Why have they written these unnecessary lines and conditions when we could do the same thing in just 2-3 lines?" Just have a look at the two codes shown below.

ameer adelPosted Jun 5, 2018, 5:35 PM
C# public enum DayOfTheWeek { Saturday = 1, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday } public static string GetDayName(int day) { if (day > 7 || day < 1) throw new IndexOutOfRangeException($"Invalid range: {nameof(day)} must be 1 to 7"); return $"{(DayOfTheWeek)day}"; }
Hrides ThakurPosted Jun 4, 2018, 11:13 PM
Very nice article sir, thanks for sharing.....