Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

Michael Sparks sparks.m at gmail.com
Sat Feb 20 09:13:06 EST 2010


On Feb 18, 4:15 pm, Steve Howell <showel... at yahoo.com> wrote:
...
>     def print_numbers()
>         [1, 2, 3, 4, 5, 6].map { |n|
>             [n * n, n * n * n]
>         }.reject { |square, cube|
>             square == 25 || cube == 64
>         }.map { |square, cube|
>             cube
>         }.each { |n|
>             puts n
>         }
>     end

This strikes me as a terrible example. For example, this is
significantly clearer:
    def print_numbers()
        for n in [1,2,3,4,5,6]:
            square, cube = n * n, n * n * n
            if square != 25 and cube != 64:
                print n

I /can/ see arguments for ruby style blocks in python, but not for
this sort of thing, or lisp style quoted expressions[1]. ie I can see
situations where you have more complex code in real life where they
will definitely simplify things.

[1] This is perhaps more appropriate because '(a b c) is equivalent
    to (quote a b c), and quote a b c can be viewed as close to
    python's expression "lambda: a b c"

However, I can also see that in simple situations - such as the
example you post - they will have a tendency to make code
significantly less clear/direct.

I suppose, if I have a choice between something (hard being possible &
simple code looking simple) and (hard things being simpler & simple
things looking harder), I'd probably personally choose the former.
This is not because I don't like hard things being simple, but because
I think that simple things are more common and making them look harder
is a mistake.

I'm well aware that's opinion however,

Regards,


Michael.



More information about the Python-list mailing list