// // Dear maintainer: //
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy
// total_hours_wasted_here = 42
Edit: to improve legibility
// // Dear maintainer: //
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy
// total_hours_wasted_here = 42
Note that on narrow windows or mobile screens this doesn't wrap and needs to scroll sideways for long lines (though these are wrapped to 60 characters), which is annoyingAlso, you only need to indent 2 spaces:
Everyone- use code blocks whenever you need them.
Mobile users- don't complain about code blocks.I'd argue the first example illustrates my point quite well (but forgive me if this gets too ivory tower). It would seem highly unlikely that the wrapping bug is intimately coupled with whatever else the component is doing. It will likely come up again in some other situation, in this project or another. After all, some users will be on this browser forever.
All this suggests we would like to factor it out, in the name of the single responsibility principle and don't repeat yourself. And the extracted component should then be thoroughly tested to it's own why. That component's why, in particular, is to work around the browser bug, so a test specification that describes precisely which versions of Windows and IE are required to be worked around is actually exactly what you want.
As to good robot control and screen geometry, I don't think that's really science fiction anymore, unless your requirements are more exacting than mine.
An executable test is good for documenting what a piece of code should do, but not always entirely sufficient for documenting why.
Sure, a unit test might just document what code is doing, because that's really the only why. But most testing effort should go into describing the why more carefully, which must be done at a higher level, as close as possible to how a user will interact with the thing.
Writing tests at the user's level and not getting bogged down in minutia requires careful factoring of the what and why. The what changes frequently, so if most of your tests are overly focused on the what, you will constantly need to update them as the code changes. The why changes much more slowly, so if your tests are written to exercise the why rather than the how, they will be resilient to changes in the implementation.
Of course, the what has to be somewhere, and when it changes there will need to be corresponding test updates, but these shouldn't require updating each individual test. The what can be kept cleanly factored out into helpers, leaving the why to remain as the essence of each test.
There will always be a pathological case. The question is what approach will increase your chances of success, what's least likely to lead to problems, what's the cost-risk-benefit tradeoff etc.
Comments detailing the intent of a non-obvious function are valuable for maintainers wanting to figure out what's happening in the code. They are written in human-oriented business-oriented language, so they don't take effort to read. The intent of the code should not change that often. If they diverge from the code, the effort of changing them should be small enough to be worth it. Ideally they should be treated as important and if they are wrong it should be picked up in the code-review.
Comments detailing just the description of what a function does, by contrast, are not valuable, since that information can be deduced from the code itself. Every time the function changes, the comment will change. Reading them is as much effort as reading the code, so if they diverge it won't be picked up as easily.
There are always exceptions to these kinds of guidelines, of course, but this at least gives motivation for why I think comments should be used in this way.
There was a window in the beginning when she still had the kid's trust and could have dug deeper, but if/once you are not a trusted party, understanding the reason because exponentially difficult.
To your point, it applies to everyone. I remember social courses at the uni about how some classes of workers would obfuscate key parts of their jobs to protect themselves from having client/managers get their nose into it.
In that sense getting to understand the core reason might often be the biggest chalenge. A bit like how finding why a bug occurs is more than half of the solution already.