by seanmcdirmid · 12y ago · 0 comments
Whatever their benefits are, this is not true at all. Comments are expensive to write and maintain. They are VERY VERY expensive to maintain because there is no automated way to test them.
Reason: In Software Archeology (a.k.a. maintaining legacy code) you are often happy to get any kind of clue as to what went on inside someones head. Maybe they saw an edge case?
Of course you should write self-documenting code with variables and function names that explains most of it but when you either have to
1. factor out a new function
do_this_to_fix_that_weird_thing(weird state)
or
2. have to add a line
state == weird ? fix = fix+1:continue // weird is a weird state that sometimes occurs even though vendors api docs says otherwise.
please think twice.
Outdated comments are a problem but very often a problem I'll happily deal with compared to not having them at all. If a comment doesn't make sense you can also try checking VC history.
3. fix_bug_that_occurs_even_when_api_docs_say_otherwise(weird)
A comment on its own isn't inherently harder to maintain any other piece of code or documentation. Sure, it's not zero cost, but I find more often than not they exceed the cost associated with not commenting.
Some system of backrefs could handle this, of course, but I'm not aware of anything in use...
Comments are highly valuable but like any tool they can be abused, or done in such a way that they don't make things better.