8 ms·
Python significant white space. Really, that's what preventing me for ever liking Python.
by wazoox 14y ago
Python significant white space. Really, that's what preventing me for ever liking Python.
- coldtea 14y agoGet an editor that shows whitespace. (Non)Problem solved. Not to mention you should indent your code exactly the same way (in a consistent format, either tabs or spaces) with how you'd indented Python code.
- jeremyjh 14y agoIt isn't totally solved. For example, you cannot write a lambda that contains a line-break. Its not a big problem, but it is a trade-off.
- nnq 14y agosignificant whitespace is not why you cannot write a lambda that contains a line-break. the problems are not really related. just ditch the difference between statements and expressions and allow multi-line expressions. true, then it will no longer be Python but a whole different language :)
- brendoncrawford 14y agoPut this in a text editor and run it in python: print(reduce((lambda x, y: x + y), xrange(10))) print(reduce((lambda x, y: x + \ y), xrange(10))) HINT: It runs.
- sylvinus 14y agoOpinions on Python aside, I'd never hire somebody saying something like that at an interview, even about a language I don't like. You should really look past petty details when evaluating any tech and come up with actual arguments.
- nnq 14y agoReally, why? You wouldn't hire someone that has some "language aesthetic preferences", although a bit different that the mainstream ones? He said "preventing me for ever liking Python" not "I'll never touch it because of this".
- pyre 14y agoThis is really the same as saying, "I won't work for company X because I don't think the brackets in the C++ code should be on the following line[1]!" [1] E.g.: int main() { } vs. int main() { } This is an apt analogy because most companies will have some sort of code style guide that you have to follow, which doesn't make "coding at company X where bracket placement is enforced" much different from "coding in Python where whitespace is enforced." I've yet to come across someone that had a severe hatred of Python due to the significant whitespace that was a programmer I respected. The last person that I knew (who had a visceral hatred of Python whitespace) wrote Perl code like this: sub func1 { shift->func2(shift)->func3(@_) } or sub func1 { grep { $_[0]->func2($_) } $_[0]->func3() } Note: These are literally code samples with the function names changed. I don't know any Perl programmers that would condone this sort of code. It's a maintenance nightmare, especially since these were not one-off instances. Seems to me that the people that have a hatred of Python's handling of whitespace don't like being 'constrained' by their language, and are probably happier with Ruby or Perl.
- berntb 14y agoThere are some problems with the whitespace in Python. I wrote some code with lots of nameless functions as input parameters (think JavaScript style or Ruby blocks), which of course was an ugly pain to port to Python with no multi-line lambdas. List comprehensions is another example -- a kludge coming from that the lack of multi instruction lambdas stop real map functions. (The fun part is that this necessity is touted as something good, instead of admitting that it is unnecessary complexity to learn.)
- spacemanaki 14y ago
- nnq 14y agoI agree, "language aesthetics" matters ...that's why I hate variable prefixing with "$", "%" or "@" :) (and out of all ideas PHP could have gotten out of Perl, it had to be this one, and in a laughable way that makes it useless as arrays also use "$") but I could understand Larry's reasoning that "things that are different should look different" and I wouldn't avoid the language just for this reason.
- Ologn 14y agoWhen programmers discuss Python on the web, this comes up again and again. I agree with you - it is a minus for me in terms of using Python. There are "solutions", there are people who say you get used to it, there are people who say it does not matter, yet it comes up again and again. I guess it does matter, to some of us at least. I can open up a text editor and start writing C, or Java, or Perl, or PHP - all without that much thought on whitespace, indentation etc. I can later run indent -kr, or perltidy, or astyle and so forth and make the code I banged out look nice and tidy. Sometimes I feel like doing the nice indentation myself while coding, sometimes I do not and let the scripts do it. With Python "there is one way to do it" and you have to think about indentation while coding. It is annoying. It is like Java and exceptions, forcing me to put try/catch loops everywhere and messing up my scope - even for a little prototype program which will be run once and will never need to catch an exception. It is treating me like I am an idiot and forcing me to work in a regimented manner. When I first learned Python, at one point I decided to put a do/while loop in my program. I was not able to discover how this was done in documentation. I go on IRC #python and am told Python has no do-while loops (which I later confirmed is true). I was told, and I am assuming the source knows more than me, that this is due to the indentation system. One screwy thing done as a result of another screwy thing. There are a lot of nice things about Python. The code is clean and understandable. It sometimes allows you to do in 2-3 lines what might take 10 lines in another language. And so on. But some programmers feel certain aspects of it are drawbacks, and these things are not easily dismissable. If they were, they would not be brought up again and again.
- cpenner461 14y agoSo technically not "do/while", but: while(some_condition): do_stuff
- jstanley 14y agoMore like: do_stuff while(some_condition): do_stuff
- cpenner461 14y ago
- PommeDeTerre 14y agoWhen you're writing code in Perl, Ruby or some other language, do you normally not use any indentation? Do you leave all of your code left-aligned?
- wazoox 14y agoI didn't say I hate Python, mind you; but I don't like its significant whitespace, like some don't like Lisp for its parentheses and Perl for its sigils. I'm using Python from time to time, but I wouldn't spontaneously use it for my personal projects, I prefer Perl for that. The only languages I really wouldn't want to work with is Java.
- wiremine 14y agoI used to think this was a drawback. Then I started using Python full time four years ago. Significant white space encourages readability, and readability (IMHO) encourages maintainability. There are a numbers of things to dislike about Python; however, after you used the language for a while, you realize significant white space isn't one of them. It is like saying lisp's parentheses are ugly: sure, you might not like them, but they are a huge reason the language (and, really, the way of thinking about code) is so powerful.
- PySlice 14y agoPython significant white space is just like nudism. At first you think something essential is missing (clothes, curly braces), then you notice that it wasn't really needed at all, and everything becomes freer and simpler.
- jrockway 14y agoEnglishalsohassignificantwhitespace.
- lutusp 14y agoNot a fair comparison -- English prose doesn't care how much whitespace appears between words, only that there's more than none. Python definitely cares how much. Don't get me wrong -- I like Python and I use it a lot, but its reliance on syntactically significant whitespace isn't in the plus column.
- jrockway 14y agoTry submitting either of our comments to a reputable publication. I doubt the editor will preserve our whitespace. English has well-defined whitespace rules, as does nearly every programming language. Every programming language style guide I've ever read has talked about indentation, so you have to indent according to rules no matter which language you use. Have you ever thought to yourself, "wow, there's no way I'll be able to finish this task on time because I have to indent according to Python's rules"? I'm guessing no.
- lutusp 14y ago> Try submitting either of our comments to a reputable publication. I doubt the editor will preserve our whitespace. True, but it's because changing the whitespace doesn't break the prose. But in Python it certainly breaks the code. > so you have to indent according to rules no matter which language you use. Sort of. I've written any number of programs in languages that use braces as delimiters, but very lazily, then used a beautifier to fix things up at a keystroke. I agree with your point that the source must eventually follow accepted formatting, but it's not true that I necessarily need to pay attention to that (as I do in Python). Some of the better beautifiers even enforce optional style choices, like turning this: function_name(variables) { Into this: function_name(variables) { Automatically. The latter style has pretty much taken over since I started programming 40 years ago, to the degree that I've come to like it. I emphasize I like Python and I find its advantages far outweigh the whitespace issue on my personal radar. > Have you ever thought to yourself, "wow, there's no way I'll be able to finish this task on time because I have to indent according to Python's rules"? I'm guessing no. You're right, but only because my editor automatically manages Python indentations in most cases, so I don't think about it any more. The one caveat are Python source files that, from time to time and for various reasons, get infested with tabs. Then things get complicated as I try to get rid of the tabs without destroying the program's logic. IMHO tabs should be outlawed.