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