Review of "Clean Code Cookbook" by Maximiliano Contieri

Review of "Clean Code Cookbook" by Maximiliano Contieri

·

3 min read

Maximiliano Contieri has worked in the software industry for 25 years while teaching computer science at Universidad de Buenos Aires. He’s also written articles about clean code, refactoring, and code smells on popular blogging platforms and in conferences. Maximiliano champions declarative and behavioral code utilizing software fundamentals to build elegant and robust solutions.

The book “Clean Code Cookbook“ is an insightful and practical guide that covers a wide range of topics to help developers identify areas for improvement in their code. By using real-world examples in different languages such as JavaScript, Python, and Java, this book provides a comprehensive collection of recipes designed to improve code readability, maintainability and scalability.

The book is divided into 25 chapters, covering from basic concept of clean code to other fundamental concepts such as readability, coupling, testing, security and extensibility.

At the beginning of the book, the author defined what clean code is:

“Clean code is easy to read, understand, and maintain. It is well-structured, concise, and uses meaningful names for variables, functions, and classes. It also follows best practices and design patterns and favors readability and behavior over performance and implementation details“.

In addition, Maximiliano introduces the term “code smell“, which he describes as a piece of code required special attention because it indicates opportunities for improvement .

In the second chapter, author represent an important concept called MAPPER (Model: Abstract Partial and Programmable Explaining Reality) that frequently appears throughout the book and serves as a part of the theory behind all clean code recipes.

The rest of the book is filled with real-word examples of code smells and how we can improve them step by step. Here are some useful recipes that the author mentions in the book:

  • Removing double negatives: the author recommends using positive wording for boolean variable names, as this makes the code easy to read and understand:

      // ❌ should not
      if (!work.isNotFinished())
    
      // ✅ should
      if (work.isDone())
    
  • Removing dead code: the book emphasizes the importance of eliminating unused or obsolete code because developers often keep it “just in case“. Dead code negatively impacts maintainability and violates the KISS (Keep It Simple, Stupid) principle.

  • Renaming bbstract names: to keep code concise and aligned with real-world concepts, the book suggests replacing abstract names with concrete ones using MAPPER approach:

      // ❌ should not
          final class MeetingsCollection {}
          final class AccountsComposite {}
          final class NotesArray {}
    
      // ✅ should
          final class Schedule {}
          final class Portfolio {}
          final class NoteBook {}
    
  • Creating null objects: the author introduces the use of null objects to avoid null reference, simplifying code and improve safety :

      // ❌ Should not
      class RealLogger {
        log(message) {
          console.log(`Log: ${message}`);
        }
      }
    
      function processTask(logger) {
        if (logger) {
          logger.log("Processing task...");
        } else {
          console.log("No logger provided. Skipping log...");
        }
      }
    
      // ✅ Should
      class RealLogger {
        log(message) {
          console.log(`Log: ${message}`);
        }
      }
    
      class NullLogger {
        log(message) {
          // Do nothing
        }
      }
    
      function processTask(logger) {
        logger.log("Processing task...");
      }
    

One particularly helpful aspect of this book is how the author frequently explains technical terms, either those referenced elsewhere in the book or commonly encountered in software development. This make the content accessible to reader of varying experience levels. For example:

In conclusion, Clean Code Cookbook is a valuable resource for developers who strives for producing quality software with a focus on readability and scalability. You can purchase the book and explore more clean code recipes on O'Reilly: Clean Code Cookbook" by Maximiliano Contieri on O'Reilly