Clean Code And Code Smells


Clean Code

The significance of writing code that is simple to read, comprehend, and maintain is emphasized by Robert Martin in his book “Clean Code: A Handbook of Agile Software Craftsmanship.” He contends that clean code is more enjoyable to produce and work with in addition to being more effective.

After reading this book, I’d like to make it a habit to pay more attention to the names of my variables and functions. Martin contends that a variable or function’s name should precisely explain its function so that other developers can more easily grasp it. For instance, it would be more suitable to use the variable “numberBooks” rather than the variable “x.”

I also want to start breaking down complicated functions into smaller, easier-to-manage portions more frequently. According to Martin, functions should only have one level of abstraction, and any that carry out numerous tasks should be split up into separate functions. It is simpler to test and easier for other developers to grasp the code when complex methods are broken down.

“Martin, Robert C. Clean Code: A Handbook of Agile Software Craftsmanship. 1st edition, Pearson, 2008.”

Code Smells

Common code smells, or patterns or indicators that a codebase may require significant refactoring, are named by Martin Fowler in his book “Refactoring: Improving the Design of Existing Code.” The “Long Method” is one of the code smells that Fowler mentions. A lengthy method is one that executes a lot of tasks and has a lot of code.

Writing lengthy procedures is one thing I desire to stay away from. Long methods, according to Fowler, make code more challenging to comprehend and test. It is simpler to test and easier for other developers to grasp the code when lengthy methods are broken up into smaller, more digestible portions.

“Fowler, Martin. Refactoring: Improving the Design of Existing Code. 2nd edition, Addison-Wesley Professional, 2018.”

Summary

In conclusion, I want to start naming my variables and functions carefully, splitting up complicated functions into smaller, easier-to-manage chunks, and refraining from writing lengthy methods that make code more challenging to understand and test. These guidelines will result in a more readable and maintained codebase.

Print Friendly, PDF & Email

Leave a Reply

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