On Thu, May 30, 2002 at 12:00:19PM +0200, Newton, Philip wrote:
> Paul Makepeace wrote:
> > On Thu, May 30, 2002 at 08:44:54AM +0200, Newton, Philip wrote:
> > > Unfortunately, myfunction() "return;"s if it doesn't know 
> > > what to do with 'input'
> > 
> > Why not just explicitly return undef?
> 
> Oh, I dunno. I just kind of thought "return;" was cooler, I guess.

I tend to regard any subroutine that does return undef; instead of
plain return; with a degree of suspicion. I then look carefully at the
rest of the subroutine to see whether it's explicit that it returns undef
for this case, or whether it's just returning falsehood.

If it's only returning falsehood then in my opinion it would be more
useful (and therefore better) by being more general and returning nothing.
That way it becomes useful in both scalar and list context.
With return undef; it pollutes in list context.
(And yes, if I want undef into a list, I can write C<scalar> before it,
which is simple.
The code to detect a list of 1 item that is exactly undef and replace that
with () is sufficiently non-trivial that I can type this sentence faster
than writing it in this e-mail. And the falsehood return of (undef) could
get confused with a legitimate 1 item list that happens to contain undef.)


So I don't regard "return;" as cooler - I regard "return;" as more generic,
and therefore better (in the general case) as I prefer more flexible
interfaces.

Nicholas Clark

Reply via email to