15
Spent 4 hours debugging a single missing semicolon in Python
Tbh I used to think syntax errors were no big deal because most editors catch them. But last week I was building a simple calculator script and forgot a semicolon after a function call. It took me from 7pm to almost 11pm to notice it was just one stupid character. Now I triple check every line before I even run the code. Has anyone else lost hours to something this small?
2 comments
Log in to join the discussion
Log In2 Comments
butler.brian26d ago
Found yourself a good example of why Python's whitespace rules can actually work against you. I had a similar situation a few years back where a missing colon at the end of an if statement made my entire program run but give wrong results. The interpreter just kept moving past it without error. Ended up stepping through line by line with a print statement on every variable until I saw the pattern break. Sometimes the simplest mistakes are the hardest to catch because your brain fills in what should be there.
1
ivanlewis25d ago
Hold on @butler.brian, I gotta push back a little here. Missing a colon isn't really a Python whitespace problem, it's just a syntax error. The interpreter literally tells you "SyntaxError: invalid syntax" and points to the line. I've done it plenty of times myself, but the traceback always catches it for me. Maybe it depends on the Python version or something weird with how the if statement was structured, but I've never had the interpreter just skip it and give wrong results. Sounds more like an IDE or editor issue where the whitespace tricked your eyes into missing the error message. Still, your brain filling in the blanks is a real thing, I'll give you that.
4