in reply to Re: Re: Re: Re: Re: Autoboxing: Yes or No?
in thread Autoboxing: Yes or No?
mirod wrote: If I use a Null Object I cannot write if( $elt->first_child) {...} anymore.
Ovid begs to differ :)
package Null::Object; use overload 'bool' => \&bool; my $self; sub new { $self ||= bless {}, shift } sub AUTOLOAD { $self } sub bool { return; } package main; my $null = Null::Object->new; $null->foo->bar->baz; if ($null) { print "We shouldn't be here!"; } else { print "We are false!"; }
That might need a bit of tuning, but you get the idea.
Update: I just noticed that you mentioned overload, so my bit of code is not news to you :) On the other hand, if clean null objects is the only benefit of autoboxing, then I again can't see much of a benefit to them. I might also add that null objects should be the exception rather than the rule, thus the performance impact should be minimal (I hope).
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re(6): Null objects in boolean context
by rkg (Hermit) on Jan 01, 2004 at 22:57 UTC | |
by tilly (Archbishop) on Jan 02, 2004 at 00:54 UTC | |
by Ovid (Cardinal) on Jan 01, 2004 at 23:13 UTC | |
|
Re: Re(6): Null objects in boolean context
by mirod (Canon) on Jan 02, 2004 at 01:41 UTC |