4 ms·
I can't even tell you how many hours I've lost due to someone committing an incorrectly indented line in python. This often happens during merge conflicts, for
by t0mbstone 7y ago
I can't even tell you how many hours I've lost due to someone committing an incorrectly indented line in python. This often happens during merge conflicts, for example.
Because logic in python is interpreted via indentation, it's very difficult for python to realize when a line is indented incorrectly. It just assumes that if a line is indented a certain way, it was intentional.
In programming languages like Ruby or Javascript, indentation is stylistic and has no effect on the logic. You can actually use the "auto-indent" feature of many editors, and you can use linting tools to ensure formatting. If you have an extra "end" or an extra ending bracket, your IDE can immediately warn you. Not so with python!
- psv1 7y ago> very difficult for python to realize when a line is indented incorrectly. It just assumes that if a line is indented a certain way, it was intentional. How is this different from some language not realising that a statement should be inside of the curly brackets instead of outside?
- dreamcompiler 7y agoNo compiler can read your mind. But in a language with brackets, the compiler can at least determine scope even when things are poorly-indented. In Python it can't in a lot of cases. It's like static type checking: The class of errors the compiler can catch is larger when it's present. Likewise, with visible scoping characters, the class of errors the compiler can catch is larger than when they are invisible.
- psv1 7y ago> But in a language with brackets, the compiler can at least determine scope even when things are poorly-indented. Yes, but can it determine scope if things are poorly-bracketed? Because that's the fair comparison.
- smt88 7y agoPoor bracketing almost always causes syntax or compiler errors. As long as you have a language that's block-scoped (which is true of modern JavaScript and most other popular languages), you'll get an error if you make a bracketing mistake. That's not true of indent mistakes. Semantic whitespace is lossy -- there's data contained in those brackets that some people think is low-value that it's expendable for the sake of saving keystrokes, but it does have value in practice.
- fuzz4lyfe 7y agoWith Python, generally speaking, if you are more than a few indentations deep you are doing something wrong. Flat is better than nested
- dreamcompiler 7y agoThat's a good heuristic for a programmer but it's no help to a compiler.
- kstrauser 7y agoI've lost approximately zero hours to indenting or formatting issues in Python or other languages. Unit tests usually do a good job of catching unexpected behavior quickly.
- smt88 7y agoFor some of those issues, you could type brackets instead of unit tests. Brackets are a lot less work.
- ledauphin 7y agofor all of these same issues, using a decent editor and a linter saves approximately the same amount of work. every time this discussion comes up, it's clear that people simply aren't willing to accept that this is a solvable problem, despite the many people who always come out of the woodwork to insist that we've solved it. Is it really that hard to accept that someone out there may have solved something you haven't?
- smt88 7y agoAs people have said in other comments, no static analysis can read your mind. You can have valid Python that contains logic errors due to indentation mistakes, and you can only catch it at runtime. Period. That said, everything is a trade-off. Semantic whitespace has downsides, but if the upsides outweigh, then it's a great idea. At this point, I have no idea what the upsides are, other than saving a few keystrokes (which truly is solvable with a good editor). It's like removing the ending semicolon in JavaScript. Sure, it almost never causes a problem, but sometimes it does, so why do it?
- kstrauser 7y agogotofail (https://www.imperialviolet.org/2014/02/22/applebug.html https://www.imperialviolet.org/2014/02/22/applebug.html) was written in C with brackets and everything.
- slykar 7y agoUsing python for about 5 years or more now and never had an issue with the indentation. If you are using notepad as an editor then maybe this could be an issue? Every other editor I've used validates the syntax and quickly catches misaligned statements. Auto formatting works too.