2 ms·
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
by dagw 14y ago
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.
- kenbot 14y agoSounds to me like tests could have helped your code far more than any comments would have.
- dagw 14y agoSome 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.
- kenbot 14y agoThat'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.
- dagw 14y agoTests 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.