Problems? Is your data what you think it is? | |
PerlMonks |
Re: Re: Re: Re: Philosophical Perly Queuesby demerphq (Chancellor) |
on Apr 20, 2003 at 11:33 UTC ( [id://251802]=note: print w/replies, xml ) | Need Help?? |
$class = $in || ref($in);
Yeah its right.. but why? when? where? If you shrug don't use it. How many modules will break for no apparent reason due to that one singular line? I don't think that would be right anywhere, and certainly not in a consturctor. Perhaps you meant the opposite?
which AFAICT, wouldnt break any code at all. Why would it? The primary objection to this idiom (assuming you mean when it is used in a new()) is one of semantic meaning. Class->new() has a clear meaning, but $obj->new() doesn't really. Does it mean to copy the object? Does it mean to create a new object of the same type as the old? Does it mean something deeper? This is primarily an issue that detailed documentation resolves nicely. I would say that you could replace my $class=shift with my $proto=shift; my $class=ref($proto) or $proto; just about everywhere without a failure. One trap with using this idom (and about the only real trap regarding that I am aware of) is when someone accidentally mixes indirect notation with direct notation, or calls new in a strange way
most likely will create an initialized object, then use that to create an unitialized object. A hard to track down error that is thankfully rather uncommon as well. --- demerphq <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
In Section
Meditations
|
|