3
I used to think comment-heavy code was for noobs until I had to debug a 500-line function I wrote three months ago at 2am
Spent four hours tracing variable names because I skipped the // notes, never again, anyone else been burned by their own overconfidence?
3 comments
Log in to join the discussion
Log In3 Comments
young.michael1d ago
I used to think comment-heavy code was for noobs" - yeah that part got me too, I felt the same way until I hit my own wall. But here's what I'm wondering: when you finally went back to fix that 500-line function, did you end up adding comments to it or did you just refactor it into smaller pieces? Because I've found that if I break it down into smaller functions with clear names, I barely need comments at all. The comments I do keep are only for the weird edge cases where the code looks wrong but it's actually right. Like when you have to add a sleep() call to wait for some async thing that should already be done, that's worth a comment. Comments about what the function does overall though, those just seem like noise once you split things up.
7
emma961d ago
@kai_chen2 nailed it with the "don't touch this unless you understand why it's cursed" thing. For me, I always add a tiny comment right before the weird fix with the date and what broke, so future me knows it wasn't just bad code.
8
kai_chen21d ago
Totally been there. I refactored mine into like six smaller functions and threw away half the comments. Now the only comments I keep are the "don't touch this unless you understand why it's cursed" kind, like when you're doing something janky to work around a library bug.
5