18
TIL about using comments in code to debug faster
I was at a coding meetup in Austin last weekend and watched a guy fix a broken loop in 2 minutes by just commenting out sections of his Python script. He said it helps him isolate the problem without deleting anything, and it blew my mind because I always just delete stuff and then retype it later. Do you guys use comments as a debugging trick or is that just a beginner thing?
2 comments
Log in to join the discussion
Log In2 Comments
faith_thomas1mo ago
Oh man, commenting stuff out is just a crutch for people who can't commit to their code changes.
8
the_phoenix1mo ago
Straight up, I read this blog post from a guy who used to work at Google and he said the senior devs there do this all the time, so calling it a "crutch" is kinda missing the point. It's not about being unable to commit, it's about speed and not losing your place when you're deep in a bug hunt. I've personally wasted way too much time Ctrl+Z-ing my way back to a working state when I could've just had a commented out version sitting there. Plus, modern IDEs make it super easy to toggle blocks on and off so you can test stuff without the risk of breaking everything. It's a tool like anything else, use it when it makes sense.
4