3 ms·
Many years ago I asked a question on stack exchange about self documenting code. https://softwareengineering.stackexchange.com/questions/51307/self-documenting
by philliphaydon 5y ago
Many years ago I asked a question on stack exchange about self documenting code.
https://softwareengineering.stackexchange.com/questions/51307/self-documenting-code-vs-commented-code https://softwareengineering.stackexchange.com/questions/5130...
I spent many years trying to write my code well enough to not need comments. At the same time I just hit 9 years at my current job and what I’ve come to realise is although the code reads, and makes sense, it sometimes lacks context of why.
So for the last few years I’ve been trying to add brief supporting comments to explain /why/ something was done, or how it ends up in a certain state, etc.
As a result when I go back to that code week or months later I find adding functionality or fixing bugs much easier.
I try not to comment too much or too long unless I really need to.
- codelikeawolf 5y agoYou beat me to the "self documenting code" thing by 10 minutes! I never bought in to the whole "clear code doesn't require comments" belief, mainly because the clearest function in the world can't provide details about its role as part of a larger system. Also, you sometimes just have to do weird stuff to get things to work (usually because they're out of your control). Rather than trying to retrace your steps every 6 months when you look at that code, a sentence or 2 describing its purpose gets you up to speed. I've been burned by zero comments way more times than I've been burned by incorrect comments.