While working on this blog, I looked back at some old codes I had written to see if I could understand them. While doing this, I often find myself struggling to understand and remember what I was thinking at the time. This shows the importance of writing clean and maintainable code, especially when working with others. For this blog, I decided to read John Clifton’s article about tips for writing clean code, and Martin Fowler’s book on its insight to code smell. Reading them got me thinking about some habits I would like to reinforce and others I need to break.
Something that I would like to start doing is the usage of tools that can measure and improve code quality. Clifton’s article recommended the use of tools like SonarLint in the measurement of cognitive complexity to help developers write code that is functional but also more understandable. These tools can highlight possible complicated areas in code that might not be immediately obvious. For example, a method that has too many conditional branches might appear quite simple at this moment but may become a nightmare later on while debugging. Gradually, these tools will lead me towards writing more structured and readable code.
On the other hand, one thing that I want to avoid is big complex classes. The discussion on “Large Class” as a code smell by Fowler really resonates with my experiences because I often make them too big which made it really confusing to work with. A large class often does too much which is against the Single Responsibility Principle. Instead of having a large class handling multiple concerns, breaking it down into smaller classes focused on their specific responsibilities makes the code more modular and easier to test.
In conclusion, writing clean code is an ongoing process of learning and improving. From now on, I will use tools that can help guide me in my improvement in keeping high-quality code. Additionally, I will avoid large classes and functions to prevent unnecessary complexity. By implementing these changes, I aim to make my future self and my teammates much happier when working with my code.