Coding Skill: The KISS Principle and Why It’s Important

Doan Duc Tin
Goalist Blog
Published in
3 min readJul 31, 2023

1. Keep It Simple, Stupid

  • Which stands for “Keep It Simple, Stupid”, this is a design principle that suggests that software should be kept as simple as possible, avoiding unnecessary complexity and features that do not directly contribute to its core functionality.
KISS Principle Coperasion with complex coding
  • The main idea behind this is to make code easy to understand, read, and maintain for us. Besides, simple code equal to less errors, easier to debug, and more straightforward to modify or extend when needed.
  • By following the KISS principle, we can create the software that is efficient, reliable, and scalable while minimizing the chances of unnecessary bugs happened.

2. How to Apply the KISS Principle

Avoid complexity in implementations:

We should write only the necessary amount of code, our duty is making it the way most easy to understand the code’s purpose and logic, not to provided the implicit and non-sense sentences.

//=========================================
// Bad example 1
function addToNumber(a, b){
int result = a + b;
return result;
}
print(addToNumber(x, y))

// Good example 1
print(x + y)
//=========================================


//=========================================
// Bad example 2
function myFunction(){
...
if (user == null) {
return null;
} else {
return user;
}
}

// Good example 2
function myFunction(){
return user;
}
//=========================================

Write clear and concise code, self-documenting code.

Build clean, meaningful function and variable names: A function named: findMaxValue, addItemToCart, handleSendEmailwhich clearly states its purpose than findValue, addItem or emailHandler.

Efficient Logic: evaluate different implementation, keep it correct, keep it simple, avoiding unnecessary complexity. This is especially important in large codebases or when working on a team.

// Bad example: Check the word is symmetry like: ...abcddcba...
public boolean isPalindrome(String word) {
boolean result = false;
int left = 0;
int right = word.length() - 1;
while(left < right) {
if(word.charAt(left) == word.charAt(right)) {
result = true;
}else {
result = false;
break;
}
left++;
right--;
}
return result;
}
// Good example: Check the word is symmetry like: ...abcddcba...
public boolean isPalindrome(String word) {
String reversedWord = new StringBuilder(word).reverse().toString();
return word.equals(reversedWord);
}

Besides, documented code is very important. By this action, other developers can understand the code’s intent and functionality more easily, which can lead to faster and more efficient collaboration and maintenance.

Review and simplify existing code.

Try to improve the code base during features implementations, make the overall system more stable and open for future modification.

Try to aim to and simplify all the part that have a same categories, sharing similar implementation approaches with current improvement.

➡️This in overall help our application more and more maintainable, and scalable, and specify help reduce the complex for old source base.

3. Benefits of Applying the KISS Principle

  • Improved code quality: Simplicity enhances readability and maintainability.
  • Improved system scalability: Small improvements in the source base can help reduce the complex and so that our application will not turn into a “gain shit”
  • Enhanced collaboration: Simple code fosters effective teamwork.
  • Reduced development time: Effective teamwork enhances the ease of achieving our projects, targets, and goals.
  • Make everyone happy

4. Dealing with Complex Features

Acknowledge that some tasks require complexity, don’t be too scare, try to manage it through different ways:

  1. Modularization: Divide complex tasks into smaller modules or functions. This approach improves code organization and makes it easier to comprehend each component independently.
  2. Abstraction: Encapsulate complex logic within well-defined abstractions.
  3. Documentation: Provide clear documentation for complex code sections. Comments, inline explanations, or external documentation can help us understand completely what we are doing.
  4. Code Reviews: Feedback from team members can identify extra simplifications or alternative ways to achieve the task.

5. Conclusion

Finally, the KISS principle aim to maintaining code quality, readability, and maintainability. By prioritizing this, developers can create a software that is more robust, bug-free, and easier to collaborate on.

The KISS principle helps us to craft elegant solutions, contributing to a more efficient and enjoyable software development process.

Let’s continue to improve this skill together in the future, ensuring the long-term success of our projects and developer community.

--

--