[Tutor] Ruby Code Blocks vs. Python Lambdas

Carroll, Barry Barry.Carroll at psc.com
Tue Nov 7 00:41:34 CET 2006


Danny:

> -----Original Message-----
> Date: Mon, 6 Nov 2006 14:28:30 -0800 (PST)
> From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
> Subject: Re: [Tutor] (OT) Flame wars
> To: Chris Hengge <pyro9219 at gmail.com>
> Cc: Tutor <tutor at python.org>
> Message-ID: <Pine.LNX.4.64.0611061356360.24369 at hkn.eecs.berkeley.edu>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
> 
<<snip>>
> 
> Let me see if we can do something constructive.  I've been doing a
> shallow, superficial study of the Ruby language at the moment.  One of
the
> things I've been impressed about is that they've managed to make
lambdas
> look non-threatening to people with their syntactic sugar of "code
> blocks".
> 
> For example,
> 
> ## Ruby #####################
> def twice
>      yield
>      yield
> twice { puts "hello world" }
> #############################
> 
> This prints out "hello world" twice in a row: the twice() function
takes
> in an implicit "code block", which it can later call by using their
> 'yield' statement.  What the Ruby folks are doing is trying to make
the
> use of higher-order procedures look really simple.  In fact, most of
the
> encouraged idiom style I've seen so far extensively uses this code
style
> pervasively (especially for iteration), and that's very admirable.
> 
> 
> The exact functionality can be done in Python, but it does look a
little
> more intimidating at first:
> 
>      ## Python
>      def twice(f):
>          f()
>          f()
>      twice(lambda: sys.stdout.write("hello world\n"))
> 
> This does the same thing, but it looks a little scarier because the
> concepts needed to grasp his are superficially harder than that in the
> Ruby code.
> 
<<snip>>
> 

Thank you for this post.  I was in a discussion of Ruby vs. Python at
lunch today.  The consensus was that Python was much better than Ruby in
all ways.  Since I know very little about Ruby, I had nothing to add to
the conversation.  

I have struggled considerably with lambdas since taking up Python.  I'm
still not really comfortable using them in production code.  I agree
that Ruby's style is more intuative and easier to use.  I wonder if a
future version of Python could adopt this style.

Regards,
 
Barry
barry.carroll at psc.com
541-302-1107

PS
Your response to the recent unpleasantness was exceptional.  I tried to
be civil in my disapproval, but deflecting the thread back to a
constructive, Python-based topic was more effective, I thought.  Thank
you again.  
BGC
________________________
We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed





More information about the Tutor mailing list