Explain why, not what — that is my main takeaway from Chapter 4 of Clean Code
Of course, it depends on your experience level or that of your team. Sometimes, it makes sense to explain what the code is doing, especially when working with juniors or in a complex system.
But the risk is this: comments that explain what the code does tend to become outdated. Code evolves, and those comments often stay behind. Now they confuse instead of clarifying.
On the other hand, comments that explain why something was done: decisions, constraints, caveats. Those can provide real insight. Especially, when the reason is not obvious from the code itself.
Here are my key takeaways from this chapter:
✅ Comments are a failure to express something in code ✅ Do not comment bad code — rewrite it ✅ Outdated comments are worse than no comments ✅ If the code is clear, comments are usually redundant ✅ Use comments to explain intent, not to describe syntax ✅ TODOs are not excuses to leave broken things behind ✅ Avoid journal comments, noise, and unnecessary Javadoc ✅ Prefer meaningful names and structure over commentary ✅ Comments should not explain “how” something works if the code already does ✅ When a comment is necessary, write it well and make sure it stays true
Good code tells what happens. Comments should tell why.
Also worth noting: Javadoc or similar language-specific structured docs are documentation, not comments. They follow a different purpose and lifecycle.
All in all, the why has helped me a lot in the past. Apart from that, I have seen too many discussions around comments become much hotter than they actually need to be.
#CleanCode #SoftwareDevelopment #CodeQuality #RethinkCleanCode #DeveloperExperience #CommentsInCode

Kommentieren und diskutieren können Sie direkt unter dem Beitrag auf LinkedIn.