4 ms·
> In Python, everything must be indented with 4 spaces. It was a great idea…. or not? I think probably it was one of the worst idea to apply in the development
by ppeetteerr 5y ago
> In Python, everything must be indented with 4 spaces. It was a great idea…. or not? I think probably it was one of the worst idea to apply in the development industry. Not even TABS! It’s literally impossible to have a consistent indentation, especially when you have more than 2 nested loops/functions/switch.
Pretty sure that's not accurate. You can use whatever number of spaces, provided it's consistent for a specific block of code.
- elementi 5y agoUps! As you might have noticed, I'm a beginner on Python but that thing was REALLY annoying. Nice to know that you can use whatever number of spaces, but... consistency is hard to keep with spaces (I'm not able :/)
- m45t3r 5y agoAs you said before, you can use tabs. You just need to use tabs everywhere (on Python 3, on Python 2 you can pretty much mix tabs and spaces, however this is a very bad idea).
- qsort 5y agoI'm not a big fan of python but I use it a lot for quick stuff, and syntax is just a non-issue. Any half-decent editor will handle that for you (and yes, this includes Vim). Criticize the wonky static typing tools and I'm with you. Criticize the unpredictable performance and I'll join the choir. Criticize dependency management and I'll unleash my rage. But come on, this is just not a thing. IME even data analysts with non-cs backgrounds and very limited programming ability never see this as a problem. It's fine if you don't like it (I prefer my {s as well!) but I'll be honest: it really feels like a nitpick.
- m45t3r 5y agoYeah, Python even support tabs. On Python 2 you could even mix tabs and spaces, but this turned out to be a very bad idea. So Python 3 enforces that the whole file uses either X number of spaces or tabs, you can use either of them.
- politelemon 5y agoOn a related note, we've been using editorconfig files to enforce consistency across our python files. It does away with 2 spaces vs 4 spaces vs tabs.
- rich_sasha 5y agoAt one place I worked, when we couldn't agree on 4 spaces (Python standard) vs. 2 spaces (existing company standard) someone suggested Fibonacci increments of indentation levels: 1, 1, 2, 3, 5, 8 etc. Would have worked from a technical point of view.