6 ms·
Imo the whole whitespace sensitivity thing was a mistake to begin with. It makes code harder to read, harder to write and harder to parse with only the benefit
by p1necone 4y ago
Imo the whole whitespace sensitivity thing was a mistake to begin with. It makes code harder to read, harder to write and harder to parse with only the benefit of being a little easier to understand to absolute beginners (and I'm not even sure about that last one).
- gleenn 4y agoAnd harder to copy-paste!
- thaumasiotes 4y agoTechnically, it has the benefit that code cannot be incorrectly indented - it can't be formatted to look like the scope is one way when in reality it's another way.
- kimmeld 4y agoCode can absolutely be incorrectly indented in python and to make matters worse it changes the functionality of the code when it is.
- thaumasiotes 4y agoCode can be indented in a way you didn't mean for it to be. But it cannot be incorrectly indented in the sense I just described, because the indentation changes the functionality of the code. The indentation can never mislead you about the structure of the code.
- Izkata 4y agoI've seen one case where it has, where the outdent at the end of a nested loop/loop/if was wrong: it was only 3 spaces instead of matching the 4 indent, so it looked right at a glance but wasn't. Needed to use pdb to step through it and see it do the wrong thing before that stuck out.
- Entinel 4y agoI am very much not a beginner and I don't find whitespace sensitive languages hard to read. I don't find Lisp hard to read either. Or C-style languages for that matter. The sheer passion people have towards whitespace vs brackets vs parenthesis makes me question their sanity.
- TheRealPomax 4y agoCongrats: you are an outlier. That's pretty cool, and it means you can read a lot of code quite easily, which I'm sure lets you be more productive than most, but you are not like most other people.
- sweezyjeezy 4y agoAre you sure this an outlier opinion amongst regular python users?
- p1necone 4y agoWell no, I imagine that that group would somewhat self select for developers who are okay with reading whitespace based syntax. Someone who finds it hard to read is probably not going to become a regular user of the language unless they have to.
- sweezyjeezy 4y agoPython is lingua franca in data science / ML, i.e. you pretty much do have to to work in the field. In my experience the people who complain about this aspect of python are those just starting out. Dependency management would be an example of a real Python issue, not a "everyone gets used to it" one IMO.
- OrderlyTiamat 4y agoI use python extensively, and whitespace very much is an actual issue. Not a big one, but it is annoying every once in a while e.g. when copying code. Especially as autoindenting is very much hampered in that case, because the editor can't tell what the indent is supposed to be if multiple options are valid python. Dealing with braces instead is much easier. Not a deal-breaker or major issue, but an annoyance nonetheless.
- hsbauauvhabzb 4y agoI find it odd that this isn’t a configuration option in any/all language compilers. I prefer indents to braces, but understand the hate others have. Turns out AST engines could convert them relatively easily.
- p1necone 4y agoA lot of languages do have auto formatters with opinionated defaults for this. For go, gofmt is so opinionated that you can't even configure it, which is kinda cool because it means all go code that uses it will look the same. There's also rustfmt for rust and prettier for JS/TS (and I assume similar for lots of other languages I'm not familiar with), both of which are configurable, which I prefer - but I can see the upsides of a one-size-fits-all code formatting tool (especially for a language like go where a reasonably constrained feature set/syntax is an explicit goal of the language).
- occamrazor 4y agoPython has black, also not configurable.
- avryhof 4y agoBlack is pretty nice with the defaults, but it certainly is configurable these days. It can take command line options, or it can be configured in your Poetry pyproject.toml file. https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html https://black.readthedocs.io/en/stable/usage_and_configurati...
- shrimpx 4y agoThere's some evidence that indentation-based block delimiting is intuitive: People indent their blocks even in whitespace-insensitive languages.
- majewsky 4y agoIndentation-based delimiting is good for reading because it provides visual structure. For writing, it's much more effective to rely on braces or parentheses instead and have the indentation be inferred by an autoformatter. For example, with braces, I can just copy-paste a statement or block of statements from somewhere else and it will have the correct semantics regardless of what indentation the source and destination end up having, and the autoformatter will immediately fix it for me.
- kazinator 4y agoWith indentation-only based delimiting, you don't know whether you're seeing the whole thing: def check(situation): if situation.under_nuclear_attack: situation.set_alert_level(RED) -------------- bottom of window ----------------- Is that the whole function? Does it forget to launch the counterstrike? Or is there more? We don't know without scrolling down. You can change the meaning of code, without changing its whitespace sensitive diff (git diff { -w | -b }).
- mamcx 4y agoCall python "harder to read" is like call rain "harder to get wet".
- Izkata 4y ago> with only the benefit of being a little easier to understand to absolute beginners (and I'm not even sure about that last one). This one is backwards: the benefit is forcing beginners to write well-formatted code. You would not believe the insane things people just learning can come up with, when in a C-style language where indentation doesn't matter.