News for hackers. Stuff that matters.
Re:Does anyone use comments any more? by dagw on Friday July 06, 2012 @03:56AM (#4206816)
Maybe it's just me, but on several occasions I've gone back to (uncommented) code I'd written several month or years ago, and thought "what the hell is going on here? Who wrote this shit?" Those time I really wish past me had taken a few seconds to write out exactly why he had solved that particular problem in that particular way, despite how obvious it no doubt seemed at the time. There are few things more annoying than finding some 'ugly' code, fixing it, having a bunch of stuff subtly break and then finally remember that there was a very good reason why you originally wrote the code the way you did. If only I'd left a comment of two for future me, much time and anguish could be saved.
Re:Does anyone use comments any more? by kenbot on Friday July 06, 2012 @04:49AM (#4206937)
Sounds to me like tests could have helped your code far more than any comments would have.
Re:Does anyone use comments any more? by dagw on Friday July 06, 2012 @05:09AM (#4206973)
Some stuff, especially stuff connected to performance or memory usage, is very tricky to write tests for. Doubly so if it is only a problem on certain hardware.
Re:Does anyone use comments any more? by kenbot on Friday July 06, 2012 @05:18AM (#4206999)
That's certainly true. I'd argue though, that most code is in a position where good naming and tests provide sufficient clarity, without requiring free-text comments.
Re:Does anyone use comments any more? by dagw on Friday July 06, 2012 @05:35AM (#4207037)
Tests can only tell you what some piece code is supposed to do, not why its doing it the way its doing. Why do you choose to define this particular constant to this particular value, why are you using that particular data structure, why are you rolling your own version of a certain function rather than using the one supplied in the library you are using, why are you using that seemingly round about way to get to that particular result?

There are lots and lots of ways to write a function that passes a test, I want to know if there is a reason why you chose the approach you used.