Keep It Simple, Stupid

Keep It Simple, Stupid

The fundamental principle of the design is straightforward: simplicity. But it's not just about making things simple; it's about considering the perspective of someone who knows nothing about it. This empathetic approach can be observed when writing code and reviewing it months later. You might find that many lines are incomprehensible because the concepts were not simplified enough for a novice to understand. Remember, we were all beginners once.


Another mistake often made when dealing with the KISS principle is that people try to make code as short as possible. But the shortest solution is rather seldom the easiest to read. Consider the following "Non-KISS" example:


f = lambda x: 1 if x <= 1 else x \* f(x - 1)


Now look at this version:


def faculty(number: int) -> int:
    if number <= 1:
        return 1
    else:
return number \* faculty(number - 1)


Indeed, the initial version is comprehensible, but it's significantly more challenging to grasp. However, incorporating some explanatory names, specifying the types of variables, and breaking the sentence into multiple lines make it noticeably simpler to read. When designing, the primary objective should always be to make it as clear and straightforward as feasible. A typical lousy habit among programmers is creating complex and illegible "one-liners," which serves no purpose—these difficulties are likely for others, if not for the programmer, in understanding the code.