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.
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.
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;
}
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.
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.
Acknowledge that some tasks require complexity, don’t be too scare, try to manage it through different ways:
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.
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ằ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
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,...