[Python-ideas] @return?

Masklinn masklinn at masklinn.net
Thu Apr 15 08:08:19 CEST 2010


On 15 Apr 2010, at 00:11 , Mathias Panzenböck wrote:
> On 04/14/2010 11:51 PM, spir ☣ wrote:
> > On Wed, 14 Apr 2010 17:41:43 +0100
> > Conrad Irwin<conrad.irwin at googlemail.com>  wrote:
> >
> >> Changing things so that return isn't necessary at all would also solve
> >> the problem, and quite nicely, but I think that's a far-too-drastic
> >> change in semantics.
> >
> > Well actually, in _many_ languages the last expression is taken as return value.
> > (Not only Lisp&  friends, also pure OO ones like Io.)
> 
> Also in Ruby. Anyway I think this is ugly (and violates explicit is better than implicit)
Why? Functions always returning the last-evaluated expression by default is a pretty explicit rule. And it's a pretty nice default too, more useful than returning None (which is the current behavior, and if you want to argue about arbitrary stuff I'd say that's just as arbitrary if not more)

> and might even be dangerous because you "leek" the return value of the last statement. Basically you suddenly need to always write None (or nil) at the end of a function that should not return anything.
In my experience (with languages behaving that way), that tends not to be much of an issue. Most functions and methods return values anyway, so that's the general case. And it's not like you should rely on undocumented return values.

So that objection is mostly a scare-tactic, akin to the "oh noes, significant whitespace is going to kill us all" screed coming from other communities when Python comes up.


More information about the Python-ideas mailing list