by physicles · 4y ago · 0 comments
In the last year alone I’d estimate comments written by my past self have saved me dozens of hours of effort tracking down the reason why code was implemented a certain way. A couple times I’ve undertaken some refactoring that would’ve taken hours, only to find 10 minutes into the process a comment to the effect of “don’t try to refactor in that way, for these reasons” and it was correct.
Maybe my memory is just particularly bad. But if the comments are helpful to me, they’d also be helpful to someone else who didn’t write that code.
It does take practice to know when and how to write those comments though.
> But if the comments are helpful to me, they’d also be helpful to someone else who didn’t write that code.
this does not necessarily follow unless you've been extremely thoughtful in how you wrote those comments (which you may very well have been). That is, in fact, the issue most of the time — that comments are written in such a way that they serve to jog the memory of the person who wrote them, but are rarely of general use to anyone else.
But for the rest, it's exactly as you described. There is usually some workaround/shortcut being taken or there is interfacing with an external dependency that does not work as expected. In those cases comments make aware of things that the code doesn't show and can save a looot of time.