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

RFC: Objective-C style "undef accepts anything"

Thread Next
Joe McMahon
May 28, 2012 22:04
RFC: Objective-C style "undef accepts anything"
Message ID:
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.

 - 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

 - 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

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About