Hacker News new | past | comments | ask | show | jobs | submit login

It's a question of habit. If you're experienced with Python List comprehensions, they become clearer than anything else.

"The main problem I see with Ruby is that the Principle of Least Surprise can lead you astray, as it did with implicit lexical scoping. The question is, whose surprise are you pessimizing? Experts are surprised by different things than beginners. People who are trying to grow small programs into large programs are surprised by different things than people who design their programs large to begin with.

For instance, I think it's a violation of the Beginner's Principle of Least Surprise to make everything an object. To a beginner, a number is just a number. A string is a string. They may well be objects as far as the computer is concerned, and it's even fine for experts to treat them as objects. But premature OO is a speed bump in the novice's onramp. " Larry Wall, http://interviews.slashdot.org/article.pl?sid=02/09/06/13432...




You're quoting Larry "I've done more than anyone to fuck up programming languages" Wall as an authority on programer clarity?!? Um... no?

here are some examples from real python (twisted)... let's see how much clearer they are than anything else:

  ''.join([''.join(['\x1b[' + str(n) + ch for n in ('', 2, 20, 200)]) for ch in 'BACD'])
  ''.join([''.join(['\x1b' + g + n for n in 'AB012']) for g in '()'])
  msgs = [os.path.join(b, mail.maildir._generateMaildirName()) for b in ('cur', 'new') for x in range(5)]
It is code like this that makes me run for the hills... Even ignoring the list comprehensions, I use join as an example of how python gets everything backwards...

  ary.join(', ')  # ruby   - oop: tell the array to join its elements with a str
  join(', ', ary) # perl   - fun: join ary with a str
  ', '.join(ary)  # python - wtf: tell the str to join the elements of some other ary?!?


I'm quoting Larry Wall because he said something interesting.

The comprehensions from twisted were not written for clarity so they aren't good examples. The programmer wanted a one-liner to define these constants.


Asking Larry Wall about good OO/language/library design, or PoLS is like asking George Bush (either really) about effective foreign policy or human rights...

Even if they say something interesting, is it valuable information coming from that source? Should it be trusted?


"The comprehensions from twisted were not written for clarity so they aren't good examples"

no... they're real examples.


string.join(ary, ', ') # python - ok: join ary with a str

The parameters to Python's join function are in a better order than Perl's. This is expected since Perl perverts the concept of function arity.

Also, twisted is not an example of the best Python code.


yes, they did add that form after a while... (so much for one right way to do things, eh?). It seems that people still prefer the `sep.join(ary)` form more based on the code reading/debugging I've done.

"better order" is subjective and I have to disagree in this case. perl's form isn't limited like pythons as it takes any number of values after the separator. Much like ruby's "* arg" (splat arg--HN's formatting is besting me) or lisp's &rest. Lisp's (+ ...), (< ...), etc are lovely because of this property.

Twisted is an example of some of the most popular python code out there... It is representative of real world python and is what drives me away from the language (and has me running screaming away from twisted).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: