develooper Front page | perl.perl5.porters | Postings from May 2012

RFC: Objective-C style "undef accepts anything"

Thread Next
From:
Joe McMahon
Date:
May 28, 2012 22:04
Subject:
RFC: Objective-C style "undef accepts anything"
Message ID:
CAHxkc3SROFAypZe6-bw8wEJNfKUC2gh0eezxOnpH6c-Swa9RMw@mail.gmail.com
One of the things I've discovered in the process of writing Objective-C
code is that its convention that nil (the null pointer) will accept any
message - but will do nothing in response - vastly simplifies code.

I'm wondering if a pragma to enable this would be a good idea for Perl.

Advantages:
 - eliminates a lot of "if (defined $foo) { ..." checking. If $foo is
defined anfd yo send a message to it, then that goes to the object
associated (unless of course $foo isn't an object). Less code is better
code.

Disadvantages:
 - As implemented in Objective-C, the messages sent to nil simply do
nothing, and there's no notification that the message went to nil. Adding a
warning pragma for this is an option.

Finer points need to be worked out; basically I can see the result of
sending a message to undef to return undef; that will work in most
situations. In list context, I suppose it should return an empty list.

If this seems like an idea, I can invest some time in putting together a
reference implementation that could be tried out. Also, if it doesn't seem
like a good idea to discuss it here, I'l be happy to move this over to
Perlmonks.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About