2024 Public Training Schedule
December 9 – 12, 2024 – Agile Analysis and Design Patterns
Half-Day Sessions
(c) 2024 To Be Agile
In addition to sharing a common definition of what quality means in terms of CLEAN code, we also must share some common quality practices that can help us increase the quality of the code we create. These practices should be straightforward to apply so we can easily make them our habits.
Here are some of my favorite practices around creating CLEAN code:
Cohesive
Entities such as classes or methods that are cohesive how about one thing. My favorite practice for this is simply giving a behavior and name. If I can easily name something then it’s about that one thing but if I have trouble naming it because it does too many things then I know that I need to break it up into separate entities.
Loosely Coupled
Code that is loosely couple interacts with its dependencies indirectly through an interface or some other indirect method. One of the most important practices for doing this is using dependency injection either through a framework or just manually bypassing in dependencies two methods rather than having the methods instantiate them themselves.
Encapsulated
Encapsulated code is code that has hidden its details of implementation. This allows the developers to change the implementation later without other parts of the system being dependent upon them. We do this by keeping as much data and behavior scoped as tightly as possible so that only the entities that need to know about it do and the rest of the system can be blissfully unaware.
Assertive
Assertive code is code that’s in charge of itself so when we put state or data into a class the code that should manage that data should also be in that same class. Think of objects as little people that want to become self-reliant. They must have everything they need to do their jobs.
Nonredundant
Nonredundant code is code that is not repeated, not just in its form but also in its intention. If two different routines essentially do the same thing then that is considered redundant. Redundancy is not always obvious in code but we want to make sure that we follow the “one rule in one place” practice.
So these are some simple practices for improving the CLEAN code qualities. The more our industry begins to pay attention to code quality and common quality practices that we can share, the more our industry and our customers will benefit from more reliable and maintainable software.
Note: This blog post is based on a section of my book, Beyond Legacy Code: Nine Practices to Extend the Life (and Value) of Your Software.
Previous Post: « Get Crisp on the Definition of Quality
Next Post: Let Go of Perfectionism »