Refactoring tips
1 min readJun 1, 2022
- Law of Demeter-driven object design that also considers maintainability, observability, and related architectural “ilities”
- Prefer explicit coding style over implicit coding practice
- Coding style includes naming and structure conventions that do not require “comments to explain the code”. The code intent should be readable and understandable without supporting documentation when possible; “Supporting Comments / Documentation” is needed only if you are the code appears to be a workaround or due to a weird use-case constraint
- Keep an eye on conditionals — avoid them where possible by designing functions and methods expressing conditional behavior and/or using policy objects
- As much as we love OOPs, there is still value in considering a hierarchical style of coding — if you code with an “audience” in mind, then you want to start with an overview of your class object, and gradually go down the lines of the Class to see methods that are more single-resp and granular-task oriented
- Feature flags are very helpful with incremental deployment and/or rollbacks. But that is not an excuse to revert to a conditional if-else statement in your code. Try to avoid conditionals and rely on data inputs to influence release/deployment behavior
- And of course, form objects, service objects, concerns, TDD, code reviews, et al..