F
3

Just saw a friend's code and they keep putting semicolons in Python

They came from learning JavaScript first and kept adding them out of habit. It doesn't break Python, but it's not the standard style and can look messy to other people reading the code. I found a style guide from the Python Software Foundation that says to avoid them. How do you break a habit like that from a different language?
4 comments

Log in to join the discussion

Log In
4 Comments
maxf33
maxf332mo ago
Honestly, I'd just run a linter on save. It'll flag the semicolons and you'll unlearn it fast.
7
ben_lewis
ben_lewis2mo ago
Forget the linter, just delete them as you type. Your brain adapts way faster when your hands feel the mistake. I tried the linter route and it just made me ignore warnings after a while. Actually backspacing over each one builds the muscle memory. Took me about a week of writing new code before the urge to type a semicolon just stopped.
4
wendy820
wendy8202mo ago
Backspacing over every semicolon sounds like a special kind of coding torture (but maybe the painful kind that works). My linter warnings just become invisible wallpaper after two days, so I see the logic. A week of that and your fingers would probably revolt and start typing Python instead.
4
wendy820
wendy8201d ago
Forget the technical side for a second. The real trick is making it feel wrong instead of just unnecessary. Write a tiny Python script that scans your file and literally beeps at you every time you type a semicolon. That auditory feedback triggers a flinch reflex way faster than a visual warning. After a few days of your computer screeching at you like a angry smoke detector, your brain will associate semicolons with pure annoyance. It's like training a dog with a shock collar but way less unethical.
6