F
22

My code comments went from zero to 100 in two weeks

I used to never write comments in my code. Figured it was extra work and I'd remember what I wrote. Then I came back to a project after 3 days and had no idea what a function did. Took me 45 minutes just to trace it back. Now I write one line comments above any function or loop that isn't totally obvious. Has anyone else had that moment where past-you feels like a stranger?
3 comments

Log in to join the discussion

Log In
3 Comments
sandragrant
I read somewhere that writing code without comments is like leaving a note for your future self, except future you is basically a stranger who doesn't know the password to your phone. It really stuck with me because that 45 minute traceback thing? I've been there too, it's brutal.
4
garcia.wren
@sandragrant that analogy is actually backwards from what I always heard! The original quote went something like "code is read way more often than it is written" so the comments are for the stranger who inherits your code, not your future self. Still hits hard though because that stranger could be you after a week away from the project. I fell into that trap myself last month when I came back to a script I wrote in a hurry and spent over an hour trying to remember why I used a global variable instead of passing parameters. Comments would have saved me that headache for sure. The phone password comparison is clever but it misses the point that the note is actually for someone who might not even know what apps are on the phone.
3
aliceharris
Oh wow yes, @garcia.wren you nailed it with that "stranger could be you" part. I literally did the exact same thing last week with a python script I wrote for a side project - came back after a long weekend and spent forever trying to figure out why I hardcoded a path instead of making it configurable. A stupid two line comment would have saved me so much time and frustration.
2