KISS stands for Keep it simple, stupid. Or Keep it stupid simple, whatever source you trust. Legends say the KISS principle is originated in the U. S. Navy, but I couldn’t faultlessly verify this.
The concept itself however is simple as it’s name indicates: Keep it simple. Okay, now you might say: “Well thank you for wasting my time. That’s easy.” and I have to agree. This can be simple. But let me remind you: there are countless ways to describe something easy in a complex way but there might only be one that is really simple.
It’s not only about simplifying things, you must be able to take a step back and view whatever you just did from ones perspective who is totally clueless. You might have already engaged this problem by writing code and reviewing it some months after that. All of your “I’m not going to comment this shit, my arrogant cat could read this code”-lines are unreadable crap because you weren’t able to take a step back and simplify the concepts.
Your code isn’t for machines
The code you write and the code your actually execute differs largely, depending on the language and compiler used. In fact machines couldn’t care less about your code. All the code you write is for humans. You write it only once but read it possibly a thousand times. Thereby it’s your responsibility to make this as easy (and thereby quick) as possible.
Easy doesn’t always mean short
Another mistake that is often made dealing with the KISS principle is, that people try to make code as short as possible. But the shortest code is rather seldom the most easy to read. Consider the following example:
Now look at this version:
Sure, the first version is also readable, but it is considerably harder to do so. By adding a few descriptive names, type hints and splitting the line in multiple ones, it gets clearly easier to read.
How to apply the KISS principle
- Simplify and explain concepts
Try to code as simple as possible, unfold your concepts, name things properly and explain with comments where the code itself can’t (Most of the time it can!).
- Use descriptive names
As easy as this sounds, trying to find names that indicate somethings true meaning can be very challenging. You may try this by telling someone a name and let them assume what they think that is. Don’t be afraid of long variable or function names. As stated earlier, the machine doesn’t care and won’t use your name anyway.
- Try rubber duck debugging
Did you ever try to explain your code to a dumb duck? No? Try it! By doing this you may not only find bugs, you may also find gaps in your or someone else’s understanding of the current code.
I am a developer and entrepreneur from Germany. I chose studying computer science because I love building things. I am of the opinion that there isn’t one truth (especially for computer science concepts) and whoever claims so isn’t that trustworthy in my eyes. I constantly try to improve things and myself. In my spare time I support businesses by offering them most of my services for free. Beside that I am kind of addict to e-learning courses.