Software Design Principle – KISS

In this article, We are going to investigate the “KISS” software design principle’s benefits and why this principle is useful for us. Some best principles are KISS, SOLID, DRY/DIE, and YAGNI software perspective.

Let’s explore KISS [Keep it simple, Stupid!]

As we can read in heading KISS stands for Keep it Simple, Stupid. It means that the simplest, most manageable and one of the best solutions should be used for any query or task. This principle can be used anywhere in any situation even in our daily routine life. Sometimes project requirement and task are very simple but the way which we chose to perform that task, makes it complicated, which also impact on time cost and too many factors.

Find a solution as simple as possible

 

So, What you think about the above image? In the first portion, there are too many complexities and not properly manage which looks weird and also time-costly, wherein second, it’s simple and straight forward.

At CppCon 2014 Bjarne Stroustrup said the best thing which I like most and that is “Make Simple Tasks Simple!

Bill Gates said, “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”

There are some codes sample below for multiple solutions for the same thing, Now you need to decide which is best and which should be avoided?.

 //Solution 1
 string name = "Faisal Pathan";
 if (name != null)
 {
     name = "Faisal Pathan";
 }
 else
 {
     name = "N/A";
 }


//Solution 2
 string name = null;
 name = name ?? "N/A";
//Solution 1
public String GetDayNameByDay(int day)
{
    switch (day)
    {
        case 1:
            return "Monday";
        case 2:
            return "Tuesday";
        case 3:
            return "Wednesday";
        case 4:
            return "Thursday";
        case 5:
            return "Friday";
        case 6:
            return "Saturday";
        case 7:
            return "Sunday";
        default:
            throw new Exception();
    }
}

//Solution 2
public String GetDayNameByDay(int day)
{
    return day switch
    {
        1 => "Monday",
        2 => "Tuesday",
        3 => "Wednesday",
        4 => "Thursday",
        5 => "Friday",
        6 => "Saturday",
        7 => "Sunday",
        _ => throw new Exception()
    };
}

//Solution 3
public String GetDayNameByDay(int day)
{
    if ((day < 1) || (day > 7)) throw new Exception();
    string[] days = {
   "Monday",
   "Tuesday",
   "Wednesday",
   "Thursday",
   "Friday",
   "Saturday",
   "Sunday"
   };
    return days[day - 1];
}

So I suggest while writing any line of code or perform a task keep the KISS principle in mind and use it wisely. I’ll come with other principles soon.

hope you guys found something useful. Please give your valuable feedback/comments/questions about this article. Please let me know how you like and understand this article and how I could improve it.

Submit a Comment

Your email address will not be published. Required fields are marked *

Footer Logo

Subscribe

Select Categories