Notes 2021-09-05

Published on Sunday, 5 September 2021

Currently Reading

Continuing with "99 Bottles of OOP - 2nd Edition" by Sandi Metz, I am uncovering more refined approaches to object-oriented programming and tackling complex refactoring techniques.

Notes on Advanced Refactoring Techniques

Additional Refactoring Questions

After applying the initial flocking refactorings, consider these questions to delve deeper into your code's structure and identify further improvements:

  • Do any methods have the same shape? Look for methods that follow similar patterns or structures.
  • Do any methods take an argument of the same name? Consistency in argument naming can indicate areas of related functionality.
  • Do arguments of the same name always mean the same thing? Ensure that similar terms are used consistently across your codebase.
  • If you were going to break this class into two pieces, where's the dividing line? Identify potential seams for modularization.
  • Do the tests in the conditional have anything in common? Commonality might suggest opportunities for abstraction.
  • How many branches do the conditionals have? Excessive branching can complicate methods and may need simplification.
  • Do the methods contain any code other than the conditional? Non-conditional code in a method full of conditionals might belong elsewhere.
  • Does each method depend more on the argument that is passed, or on the class as a whole? This can guide decisions about method placement and responsibilities.

Squint Test

This simple yet effective technique can help you visualize structural issues in your code:

  • Procedure:
    • Place the code of interest on your screen.
    • Lean back in your chair.
    • Squint your eyes so you can see the code but not read the text.
    • Look for changes in shape or color which can indicate inconsistencies or clustering of complexity.

I find the code map feature of VSCode to be a digital equivalent of the squint test, offering a high-level overview of code structure.

Primitive Obsession

The tendency to use primitive data types (such as strings, numbers, and booleans) excessively is known as "primitive obsession." To combat this, consider creating custom classes that encapsulate these primitives and more accurately reflect their role within the domain. This approach enhances code clarity and reduces errors.


These insights further emphasize the depth and utility of techniques discussed in "99 Bottles of OOP," guiding the transformation of good code into great code through thoughtful refactoring.