2024 Public Training Schedule
December 9 – 12, 2024 – Agile Analysis and Design Patterns
Half-Day Sessions
(c) 2024 To Be Agile
Clean code is code that is understandable and maintainable. It’s design is clear, entities are well named, and developers aren’t scared to work with it. Clean code doesn’t happen by accident, it requires attention but it can make a big difference for those who have to work in the code. Here are seven strategies for writing cleaner code.
1. Adopt collective code ownership
Collective code ownership means that any team member can work on any part of the code, even if they didn’t write it. The team should adopt the same coding standards so no one can tell by reading the code who wrote it. This makes the coding style consistent and easier to work with. In addition to sharing a common coding format the team should be working from the same domain model, have common development practices, and a shared vocabulary for describing designs.
2. Refactor mercilessly
Refactoring is a central part of writing code and happens throughout the development process in the large and in the small. Developers should refactor code as they’re writing it and once a new behavior is working. Refactoring is not an excuse for writing messy code. Refactoring teaches us to build supportability into code so it’s easier to work with later.
3. Pair constantly
Pair programming is the fastest way to propagate knowledge across a team. Pair with different people every day until you find the people you pair best with, but still pair with different team members occasionally in order to continue learning from each other. Some teams pair on all tasks but you should at least pair when designing, coding, refactoring, debugging, and testing.
4. Do code reviews frequently
Code reviews are still valuable even when you pair program on everything because it gives others who you didn’t pair with a chance to see your code and give feedback. Code reviews should focus on the reasoning behind decisions and discuss design options and tradeoffs.
5. Study other developer’s styles
Reading other people’s code and learning how other developers write code is a great way to improve your skill level as a developer. Virtually every developer has his or her own style. Learning how other developers address issues can make you a much better developer yourself.
6. Study software development
Twenty years ago there were only a few good books on software development that were must-reads for developers. Today there are hundreds. Being a professional developer requires ongoing study. Doctors devote 8-10 hours per week reading up on their field. Developers should do the same.
7. Read code, write code, and practice coding
In Stephen King’s book, On Writing, he suggests that in order to be a great writer you should read a lot and write a lot. When Henny Youngman was asked how to get to Carnegie Hall he said “practice, practice, practice.” The same is true in software development. Read other people’s code, write code, and practice.
Clean code is easier to work with. Since on average code is read ten times more than it’s written it usually makes sense to put effort into keeping it clean. As you make these practices into habits you’ll find it takes no effort at all but pays back dividends quickly by making code more maintainable.
Previous Post: « Seven Strategies for Increasing Code Quality
Next Post: Seven Strategies for Better Code Reviews »