3 ms·
Python That Doesn't Suck: Whitespace-Inactive Python
- yungchin 18y agoGreat. So now you can write code that you can only get the rest of the world to use, if it's so absolutely magnificent that they'll replace their default interpreter for it? They might have also made it auto-insert the "self" method parameters, while they were at it (I'm ignorant enough that I don't understand the usefulness of those...)
- mahmud 18y agoNo reason it can't be preprocessed. It should be a straight 1:1 translation between indentation depth to an opening/closing brace (a simple push-down automaton.) [Edit: he chose to go with begin/end; let's call this a Ruby That Doesnt' Suck]
- paulgb 18y agoIs this a joke? I don't mean to be insulting if it's not, but "Python That Doesn't Suck" seems intentionally inflammatory. And as a Python coder, the idea of the parser disregarding the indentation seems silly.
- jackowayed 18y agoWell, I went with that name 1) because I couldn't think of anything better, and 2) because if you don't think python's whitespace-activeness sucks, you're not going to use it anyway. Truthfully, I think I could get used to it (I'm a rubyist myself). But I've talked to a number of people who have said basically, "I've heard it's a cool language, but I hate/will not use whitespace-activeness.
- paulgb 18y agoOh, sorry I took it that way then. For what it's worth, I went from Ruby to Python myself. At first it almost felt like an invasion of my privacy for a parser not to discard whitespace. Once I got used to it though, I couldn't go back.
- jdp 18y agoWhy is it that people hate active whitespace? I think it's great that the parser can detect where blocks end just by maintaining a nice code structure. I guess people are just against it on principle? Just in edge cases where indenting wouldn't make sense?
- jackowayed 18y agoOne question, does python have an equivalent to irb (http://en.wikipedia.org/wiki/Interactive_Ruby_Shell http://en.wikipedia.org/wiki/Interactive_Ruby_Shell)? If so, how do you get into/out of blocks?
- paulgb 18y agoYup. If you start the python interpreter, it opens up into an interactive shell. You still have to indent inside the block, and python interprets the code after you enter a blank line. ipython is an improved python shell, with tab-completion and some other cool features.
- paulgb 18y agoI think to some extent the whitespace is symbolic of a larger issue with python: the interpreter thinks it knows best. Most people still come from a "wild-west" C-family language (or worse yet, perl) where your code can be as clever and concise code as you want. To me, python's "one true way" philosophy felt too paternalistic. So yeah, I guess you could call it a matter of principle. (Python has become my main language since, but I never claimed to have strong principles :) )