5 ms·
> And I pity anyone who miscounts spaces and accidentally puts in three spaces instead of four somewhere -- this can take hours to debug and track down. this i
by Hello71 8y ago
> And I pity anyone who miscounts spaces and accidentally puts in three spaces instead of four somewhere -- this can take hours to debug and track down.
this is so hilariously wrong that it is clear that the author has never actually tried any of the things he complains about.
Python 3.7.1 (default, Oct 22 2018, 10:41:28)
[GCC 8.2.1 20180831] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> if True:
... if True:
... pass
... pass
File "<stdin>", line 4
pass
^
IndentationError: unindent does not match any outer indentation level
same error in Python 2.7.15. the caret is at the wrong place, but the error message is perfectly fine on its own.
edit: I checked the CPython source, and this message actually dates back to 2000. so unless the author was using python 1.x back in the 90s, or is dumb enough to use single spaces for indentation, the story is a complete fabrication.
- fhood 8y agoNot to mention, who hits the spacebar four times for their indentation? Actually. Do people do that?
- mikestew 8y agoTo back this up, I was at a place where vim on my Mac and the Windows editor on the machine of one of the people consuming my code would somehow munge the spacing (tabs-to-spaces, or summat). Point is, I'd see this problem constantly until I figured it out. And not once did it take more than a few minutes to fix it because, as you point out, it shows you where the problem is. And if you use PyCharm, or VS Code with Python extension, or a raft of any other editors, it'll bark at you long before you try and run the code, with circles and arrows, and a paragraph on the back of each one explaining the problem. So, yeah, the author is making shit up. And needs to learn about what the Tab key does.
- mixmastamyk 8y agoDoesn't even need to be a big heavy editor. I use the lightweight Geany and even it has indentation guides and whitespace visibility. Even so, I could probably fix such a problem without it.
- compiler-guy 8y agoI think the problem he is describing--somewhat poorly--is when the "third space" just happens to match some other scope above, and therefore is syntactically valid, but not nested the way one initially thought. Those kinds of problems can be hard to track down.
- drewrv 8y agoThese kind of problems can be solved or avoided altogether by a decent editor.
- compiler-guy 8y agoI don't see how. An editor can help you get indentations that are syntactically valid, but can't possibly know if the programmer intends the program below to print plain "foo" or both "foo" and "bar". print("foo") # x is false for the problem if x: do_something() print("bar") And to the parent who has written a lot of code but never had this problem, well, some people do.
- deleted 8y ago[deleted]
- mixmastamyk 8y agoThat's a two space error and easy to see. > never had this problem, well, some people do. Neophytes also have a lot of problems with matching braces, neither is a panacea to those folks. But one is easier to read and type for everyone else, for years to come.
- compiler-guy 8y agoIt's a two space error in a trivial example that no editor can help with. If the function is longer or their are a couple of additional levels of indentation, and it isn't a print statement, but some additional logic, it is a hard problem to spot.
- paulie_a 8y agoDo you mean using spaces or using the space bar? 4 spaces is standard but the editor should take care of that with tab that results in 4 spaces. An actual tab is just plain wrong. It is allowed of course, but those developers are wrong for doing so.