Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Re: Re: Philosophical Perly Queues

by demerphq (Chancellor)
on Apr 20, 2003 at 11:33 UTC ( [id://251802]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Philosophical Perly Queues
in thread Philosophical Perly Queues

$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?

my $class=ref($proto) || $proto;

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

my $Obj=new Class->new(@args); my $New=Class->new(@argS)->new()->foo(); # probably an error

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...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://251802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-06-16 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.