Coding Skill: The KISS Principle and Why It is Important

How to adapt a design principle that suggests software should be kept as simple as possible? The main idea behind this is to make code easy to understand, read, and maintain for us.

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 ==============================
function addToNumber(a, b){
  int result = a + b;
  return result;
}
print(addToNumber(x, y))

// Good example =============================
print(x + y)
// Bad example ==============================
function myFunction(){
  ...
  if (user == null) {
    return null;
  } else {
    return user;
  }
}

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

 

Write clear and concise code, self-documenting code.

Build clean, meaningful function and variable names: A function named: findMaxValue, addItemToCart, handleSendEmail which 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.


  RATE: 4.0 

  526 VIEW


chưa có bình luận nào ...
BÀI VIẾT LIÊN QUAN
Coding Skill: The KISS Principle and Why It is Important

How to adapt a design principle that suggests software should be kept as simple as possible? The main idea behind this is to make code easy to understand, read, and maintain for us.

BÀI VIẾT LIÊN QUAN
Deploy và Config Domain cho 1 ứng dụng Spring đơn giản trên Cloud VPS sử dụng Ngnix và Portainer

Bằng các công cụ như Docker, Cloudflare, Ngnix, Portainer. Bài viết giúp các bạn hiểu được ý nghĩa của việc sử dụng VPS, cách thức để giúp ứng dụng của bạn được truy cập ở mọi nơi

BÀI VIẾT LIÊN QUAN
Quantum Computing là gì, ứng dụng của nó trong quantum computers

Công nghệ lượng tử khai thác một số hiện tượng gần như huyền bí của cơ học lượng tử để mang lại những bước tiến vượt bậc về sức mạnh xử lý. Máy lượng tử hứa hẹn sẽ vượt xa những siêu máy tính có khả năng xử lí tốt nhất hiện nay, hứa hẹn sẽ tạo ra những tiến bộ thú vị trong nhiều lĩnh vực khác nhau, từ khoa học vật liệu đến nghiên cứu dược phẩm. Các công ty đang thử nghiệm công nghệ này để phát triển những thứ như nguồn pin mạnh hơn cho ô tô điện, tạo ra các loại thuốc mới,...