[Tutor] Ruby Code Blocks vs. Python Lambdas

Carroll, Barry Barry.Carroll at psc.com
Wed Nov 8 01:18:04 CET 2006

Hello again.

> -----Original Message-----
> Date: Tue, 7 Nov 2006 09:56:42 -0000
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Ruby Code Blocks vs. Python Lambdas
> To: tutor at python.org
> Message-ID: <eipl8s$8ab$1 at sea.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> 	reply-type=original
> "Carroll, Barry" <Barry.Carroll at psc.com> wrote
> > The consensus was that Python was much better than Ruby in
> > all ways.
> That's a little hard on Ruby. There are many good features and several
> of them are arguably improvements on Python. 

In case anybody's interested, I wasn't giving my own opinion on Ruby; I
don't know enough to have an opinion on Ruby.  Sadly I don't have time
at present to study the language right now.  That's one reason why I'm
enjoying this discussion.  

> > 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 intuitive and easier to use.  I wonder if
> > a
> > future version of Python could adopt this style.
> I think it would be difficult without adding block delimiters to
> the language, and most of the common symbols already
> have a role ([],(),{}, |, etc).

I think a solution could be found if the desire for the capability was
there (e.g. <>, ``, ...). 
> Also Guido prefers explicit definition of functions to
> anonymous ones - explicit is better than implicit is
> one of Pythons principles after all.

Correct indeed.  But lambda functions ARE anonymous.  

	"Python supports the creation of anonymous functions (i.e. 
	functions that are not bound to a name) at runtime, using 
	a construct called "lambda". 

So that principle has already been bent.  Since code blocks are more
flexible and more intuitive than lambdas, why not add them to the tool
box?  To quote some more principles:

	* Beautiful is better than ugly. 
	* Readability counts. 
	* ... practicality beats purity.

> Alan G.

barry.carroll at psc.com
We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed

More information about the Tutor mailing list