Clean Code is a book that promotes the principles of writing clean, readable and maintainable software. This book is written by Robert C. Martin, who is an expert in the field of software development. The author argues that writing clean code is essential to the success of any software project and that it is a skill that can be learned and improved over time. Reading this book is recommended for people who are on the path of professional software development. In the following, we mention some of the important points mentioned in this book.
Meaningful and descriptive names: Choosing the right names for variables, functions, and other elements of a program is an important part of writing good, clean code. Use descriptive and meaningful names for variables, functions and classes. Use names that describe what a function or variable does, rather than how it's done.
Functions and classes should be small: Functions should do one thing and do it well. They should be small enough to fit on one screen. Small functions and small classes are more reusable because they are more focused on a specific task or responsibility. Small functions and classes are easier to understand, test, and maintain.
Function Arguments: Limit the number of arguments that a function takes. A function with many arguments is hard to understand and maintain. It is also suggested that functions use object parameters instead of individual variables whenever possible.
Use clear and concise comments: Use clear and concise comments to describe the purpose and behavior of the code. The comments is not suitable for disabling part of the code, please refrain from doing so.
Don't Repeat Yourself: Avoid writing duplicate codes or copy/pasting them. Instead, implement shared functionality in functions. This will increase the reusability of your code.
Keep It Simple (KISS): Avoid over-engineering and keep code as simple as possible. Break big problems into smaller parts. Refactoring small functions is easier than refactoring a huge function.
Test-Driven Development (TDD): Test-driven development helps to ensure that the code is thoroughly tested and meets the requirements of the software. This can help improve the overall quality of the code. It also reduces the time spent on troubleshooting.
Refactor regularly: Refactor the code regularly to keep it clean. Refactoring the code increases the quality of the code. We can also solve the problem in more optimal ways every time we refactor, which helps to increase the efficiency of the program.
Single Responsibility Principle (SRP): A class or function should have only one reason to change. Functions and classes that are responsible for handling a single task are easier to understand. Also, considering that they are single-task, they are more changeable and testable.
Open/Closed Principle (OCP): Software entities (classes, modules, functions, etc.) should be open for development but closed for modification. In other words, when we want to add a new feature to the program, the previous codes should not be changed.
Liskov Substitution Principle (LSP): Derived classes should be able to be used in place of their base class without causing unexpected behavior. Polymorphism, which is one of the important concepts of object-oriented programming, is realized following the principle of Liskov's substitution.
Interface Segregation Principle (ISP): Clients should not be depend to interfaces they do not use. In other words, interfaces should include only the methods that the client needs. To apply this principle, large interfaces with diverse methods should be divided into several small and centralized interfaces.
Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both must depend on abstractions. Abstractions should not depend on details. Rather, details must depend on abstractions. Relying on abstractions can reduce dependencies and create reusability. Finally, codes can be easily changed or replaced without affecting other parts of the system.
Attention to Code Smells: Code smells refer to potentially problematic areas of code that may be difficult to maintain or modify over time. A code smell is not necessarily an error or a bug, but rather a sign that there may be a problem with the design or organization of the code. If the smell of the code is not paid attention to, it will lead to heavy losses in the long run.
The points mentioned are some of the important points of the clean code book, the understanding of which has a special impact on the professional path of every programmer.
If there is a point that has been missed and is not included in the list, please write it in the comments.
I am Reza Babakhani, a software developer. Here I write my experiences, opinions and suggestions about technology. I hope that what I write is useful for you.
leave a comment