KISS but not the band

A few people know the band kiss and their songs.
When someone is asking me, if I know “KISS” the first thing that comes in my mind is developing software.
Don´t be shocked I don´t love my software that much to kiss it. I just develop my software following the
kiss principle. 

Keep
It
Simple
Stupid

If you know the full name of the KISS abbreviation, then you´ll understand the meaning of this. Develop your methods and classes really simple and (for the first try) always prefer the straightforward solution.

Example

Let me show you a little example

Not KISS approach

If we strictly ignore the KISS principle, it may look like this:

public void printOutAllElements(List<Integer> integerList) {
      Integer[] integerArrayFromList = (Integer[]) integerList.toArray();
      
      for(int i = 0; i < integerArrayFromList.length; i++) {
          System.out.println("value: " + integerArrayFromList[i]);
      }
      
  }

When you see this code for the first time (for example cause of a bug) can you see and say where the bug is and why this bug was caused?
Why is there a cast to an array? Maybe because the one who developed this code didn´t know how to work with lists. Or why is he using and index based for for loop?

KISS approach

public void printOutAllElements(List<Integer> integerList) {
        for(Integer intElement : integerList) {
            System.out.println("value: " + intElement);
        }
    }

We deleted the casting to an array and just use the list from the method signature directly. Furthermore we replaced the index based for loop with a for loop that works directly on the elements of the list.

 

Always keep in mind to develop your business logic as simple as possible. So everyone who needs to do bugfixes or work with the code can understand, what you have done and why you´ve done it this way.

So always keep it simple and have fun following the KISS principle

Feel free to share

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.