News for hackers. Stuff that matters.
Re:I don't like Python. Does that make me a bad person? by asher on Saturday June 26, 2010 @12:15PM (#1463850)
All the popular scripting languages "do" the same things. But I prefer Ruby to Python (while still liking Python) because it feels more programmer-friendly.

    Ruby: a = %w( apple pear orange )
    Python: a = [ "apple", "pear", "orange" ]

    Ruby: a=%q/O'Malley says "Hello"/
    Python: a = "O'Malley says \"Hello\""
Python lets you use "'" or '"' as the delimiter, which solves 80% of these cases - but why not generalize the concept, as Perl and Ruby did?

In Ruby, the last expression in a function is the return value; in Python you must use the return keyword, even though there's no ambiguity.

Re:I don't like Python. Does that make me a bad person? by Goladus on Saturday June 26, 2010 @09:17PM (#1464651)
While it's true that "last expression in a function" is not technically ambiguous, because of python's statement/expression distinction leaving off the return can lead to unclear code.

For example, if there's a function composed entirely of print statements, the last expression evaluated will be the expression in the last print statement executed. But, that means you have to know that 'print' is a statement and not an expression, and that the right-hand side of the print statement is in fact an expression.

In ruby, actions like prints and assignments are side-effects and always evaluated as expressions. So if puts is the last expression in a function you'll get the return value of puts (which is usually nil I believe). That's pretty simple.

Re:I don't like Python. Does that make me a bad person? by dlsspy on Saturday June 26, 2010 @03:47PM (#1464167)

    a = '''O'Malley says "Hello"'''
Re:I don't like Python. Does that make me a bad person? by kragen on Saturday June 26, 2010 @05:53PM (#1464360)
My usual approach to the first one in Python is:

    a = "apple pear orange".split()