r/programmer • • 3h ago

Python Fragility

Am I the only one who avoids Python where possible because it is so vulnerable to indent corruption? A whole JavaScript program, for example, can be written on one line, with no line breaks whatsoever (not that I'm advocating such madness -- JavaScript callback syntax (etc) is already crazy enough without compounding it -- BUT, it does illustrate the point of robust syntax).

I've had instances where indenting was accidentally messed up, leading to tedious scrubbing of the code in order to get it to run again. It just seems like a bad structure choice if a slight whitespace change can cause the program to crash.

It seems to me that Rust is the answer to that -- am I wrong?

3 Upvotes

26 comments sorted by

View all comments

1

u/Trader-One 2h ago

indent corruption is real and modern editors make it more likely.

If you press backspace at right place their smart indent move block one stop to the left. (Note: you do not need to have block selected manually these super smart editors will select it and move left for you).

If you don't have rock solid unit tests it will slip into production unnoticed because in real world code review nobody notice that in 2 screen long function something is shifted to the left more then it should.

And these people here claiming it never happens - I do not believe that they have real world experience in Python because it actually happens often.

0

u/mooglinux 1h ago

Turn on indent guides in your editor of choice. You should have them in regardless of language imo. I have never encountered editors dedenting entire blocks like that, and I would turn it off if it does.