🐿️
19

Vent: My mentor told me to stop over-commenting my code and I fought it for like two weeks

I was writing a comment for literally every single line in my Python scripts and she showed me how self-documenting code with clear variable names actually made my projects easier to debug after I tried it on a 200-line file last month.
2 comments

Log in to join the discussion

Log In
2 Comments
mary462
mary46223d ago
Oh man, that's such a good point about the debug part. When you said it made the code easier to debug after you tried it, did it also help you spot bugs faster while you were writing the code in the first place? Like, I'm wondering if picking good variable names forces you to think through the logic more carefully as you go. Or was the benefit more about coming back to it later?
7
thomas862
thomas86223d ago
Oh man, I feel this one deep in my soul. I was the exact same way when I first started coding - every single line had a comment explaining what it did like "this adds 1 to counter" or "this opens the file." It took my senior dev literally walking me through one of my old scripts that had become a complete nightmare to maintain before I got it. She showed me how renaming "x" to "total_cart_items" and "y" to "discount_percentage" made the whole thing read like plain English. Now I comment maybe 2 or 3 times per 100 lines tops, usually just explaining the why behind a weird edge case or a workaround. It feels wrong at first but it really does make debugging so much easier when you come back to the code six months later.
6