Skip to content

Explained: What is the KISS Principle?

  |   5 min read

What is KISS and What Does it Stand For?

"Keep It Simple, Stupid!" is a design principle which is very commonly referred to in software development, but is applicable to pretty much any system or process in any industry.

What Does the KISS Principle Try to Achieve?

Once you know what it stands for, KISS becomes almost self-explanatory: it's often better to try and keep things simple. In principle, simpler systems work better than overly complex ones due to the massively increased scope for error in complicated systems.

It sounds kind of obvious, but you should try to avoid unnecessary code complexity where possible and aim to design with simplicity in mind. I highlight the word "unnecessary" because you're never going to be able to avoid all complexity, but you should try not to over-complicate things where possible.

How Can I Keep Things Simple?

Break It Down

Being able to break down your problems into smaller and smaller ones is one of the best ways to simplify your code. Have you ever seen a function like this?

const doSomethingAndThenSomethingElse = () => { ... }

The "And" in the name of that function is an immediate red flag that it's got too much responsibility and needs to be broken down further. The aim is to write smaller classes and functions which only solve one single problem. If you have a lot of conditions in your function, break these out into smaller functions.

Don't Solve Problems You Don't Have

It can be tempting to go overboard and try to future-proof your code to the fullest extent, catering for all future eventualities and possibilities. The problem with that is you will end up introducing complexity with no immediate value. It could result in issues coming to the surface which need complicated bug fixes, wasting time and energy on something you didn't need in the first place. This is actually a principle in itself: YAGNI (You Ain't Gonna Need It) which compliments the KISS principle rather well.

What Are the Benefits of Keeping Things Simple?

Speed and Flexibility

I'm going to resort to the much-loved the LEGO analogy: when you manage to have your many classes and functions which all solve their individual problems it's like having lots of different LEGO bricks. You can stack them together quickly to create something new and easily switch out one brick for another to achieve different outcomes. This ultimately results in being able to solve new problems faster as well as diagnosing and fixing existing issues more efficiently.

Maintainability

Furthering what I've talked about above, your code should also result in being more easily readable and understandable by anyone who is new to the codebase. That is a big advantage when thinking about maintainability; lowering that mental barrier to entry means it won't take long for other developers to figure out how best fix issues or extend the codebase to add new features.

Code Quality

You should find that by focusing writing functions with a single purpose, you will in turn be able to pay more attention to how you can perform the required task in the most efficient and concise way possible to produce the best code for the job.

Testing becomes easier too! You should be able to write bullet-proof unit tests which make sure your functions do what you need them to in all situations. The test cases are always going to be simpler when your functions don't try to do too much.

Scalability

Going back to the LEGO analogy, the theory is that you can keep adding bricks to scale up and up as much as you need. I realise the reality is never that simple, but it goes some way to helping avoid the issues scaling up more complex systems.

KISS Can Be Subjective

Which of the following would you describe as "simplest"?

const getWeekday = (month: number) => {
    switch (month) {
        case 1:
            return "January";
        case 2:
            return "February";
        case 3:
            return "March";
        case 4:
            return "April";
        case 5:
            return "May";
        case 6:
            return "June";
        case 7:
            return "July";
        case 8:
            return "August";
        case 9:
            return "September";
        case 10:
            return "October";
        case 11:
            return "November";
        case 12:
            return "December";
        default:
            throw new Error("month must be in range 1 - 12");
    }
};
const getWeekday = (month: number) => {
    if (month < 1 || month > 7)
        throw new Error("month must be in range 1 - 12");

    return [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December",
    ][month - 1];
};

Whichever one you prefer, you can bet it's not going to be the same for everyone! It doesn't necessarily matter and it's not something to get too caught up in, but it's something to be aware of.

Closing Comments

One thing worth noting is that you may find that principles like KISS can conflict with other principles. For example, DRY (Don't Repeat Yourself) in its most basic over-simplified definition states that you should never duplicate code, however there will be times where a little bit of code duplication actually reduces complexity and saves you headaches in the future.

More in the "Explained" Series

Thanks for reading! I hope you enjoyed the post and found it useful. If you liked this, why not take a look at more posts in the "Explained" series

Previous: I'm now a Brave Verified Creator

  |   2 min read

I've signed up as a Brave Creator so I benefit from Brave's amazing new approach to monetizing content on the web. If you're a content creator, you should sign up too!