6 ms·
I think it's an unfortunate result of people complaining about significant whitespace in Python.
by leadingthenet 5y ago
I think it's an unfortunate result of people complaining about significant whitespace in Python.
- Akronymus 5y agoSignificant whitespace in python is annoying indeed. Altough, specifically in python (because the mixture of statement based, not strongly enforced type system and the whitespace). In f# I actually really like the significant whitespace.
- leadingthenet 5y agoI don't understand how it's ever an actual problem and not just people being lazy / literally just starting out learning the language. Every Python editor / IDE is capable of, and immediately will, notify you of any formatting issues of the sort. Python also has great, trivial to use autoformatters like black[1] that essentially all production code should use and which ensure that you never, ever have to think about this again. What realistic scenario is there where it actually makes sense deviating from the standard the language is trying to enforce? And even if you can think of one (I honestly cannot), is now having to write an “end” keyword all over your code really a tradeoff worth making? [1] https://github.com/psf/black https://github.com/psf/black
- DNF2 5y agoMy problem has been that I sometimes lose indentation, by accident, and this can break or, worse, alter the behavior. It is also a nuisance when I want to copy-paste code from somewhere else, and it doesn't go smoothly. Once I needed to incorporate code from a colleague who used 2 spaces for indentation. That was a nightmare.
- leadingthenet 5y agoYou're simply admitting to not using a formatter. Both Black or PyCharm's Ctrl+Alt+L format should be able to handle that scenario. You can enable it to run automatically on file save in either (n)vim, VSCode, or PyCharm. Or as a git hook. Or in a CD/CI pipeline. Seriously, simply installing black through your favourite package manager and running `black .` in your project directory takes like 10 seconds flat. Done, you never have to think about tabs / 2 spaces / 4 spaces ever again. Please use these tools, I promise both your own and your colleagues' life will be greatly improved, and it takes no effort at all to use.
- DNF2 5y agoIf you say so. I've never heard of either of those, and have only the vaguest idea of what a 'formatter' might be. Is it not a solution to an unnecessary problem? And how can a formatter fix a lost indentation that changes the meaning of the code? I do know for sure that my colleague will never use this, even if I might. Fortunately, this isn't an issue in the languages I use most of the time. (Another problem that's bothering me almost as much is that without brackets or `end` statements, the code looks assymmetrical - unbalanced and awkward, as if it's trailing off, having forgotten its purpose.)
- leadingthenet 5y ago> Is it not a solution to an unnecessary problem? You literally stated the problem yourself, so obviously not. Seeing how it’s an official tool by the Python Software Foundation, it should underline how critical it is. > I do know for sure that my colleague will never use this, even if I might. You gain value even if you’re the only one using it, as it solves the issue you mentioned having.
- DNF2 5y agoWhat? I mean, it's a solution to an unnecessary problem caused by indentation being significant. The problem wouldn't exist if whitespace wasn't significant, which was an unfortunate design choice. So it's a solution to an unnecessary problem.
- Akronymus 5y agof# has significant whitespace as well, yet I don't think it suffers from it at all. in python if you something like this: while (cond) if (someothercond) //code else //morecode somefunction() //othercode it can be unclear if "somefunction()" belongs in the else or not. This is IMO due to python being statement based. While in f# the if evaluates to a value, so the type of it would more likely than not change and thus throw out a visible error. Hence me calling out the mixture specifically.
- leadingthenet 5y agoYou make a fair point, I guess I’m just used to it now. My IDE (PyCharm) adds indentation lines, so it’s never been particularly confusing for me. I do think F# is very interesting and quite pretty, though I’ve never used it.