Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Is "ref($class) || $class" a bad thing?

by stvn (Monsignor)
on Jul 12, 2004 at 16:32 UTC ( #373652=note: print w/ replies, xml ) Need Help??


in reply to Re: Is "ref($class) || $class" a bad thing?
in thread Is "ref($class) || $class" a bad thing?

The ref $proto || $proto idiom is not bad in and of itself. It's bad when it's tossed in around blindly without documentation because it suggests that perhaps the programmer is unaware of the intention.

But that implies that people will read said documenation and even more so that if they read it, they would understand it. That can be a heavy assumption. Of course, it could be argued that if they don't read it, it's their problem anyway.

Personally, I tend to be a paranoid programmer, and I am very concerned about my modules working as I intend and sending feeback/warnings/errors back to the user if they are not used correctly, regardless of the documenation.

As with anything in Perl (or even life), I would hate to automatically declare anything wholly without merit (with the possible exception of bell peppers -- they're just gross), so I'd argue that this idiom has it's place so long as someone knows why they've put it there.

I guess I am not arguing so much that the idiom is bad, but that maybe teaching it soooooo widely is. I know that I use it, and have never really stopped to consider the implications of it being misused (I mean, all the cooool kids use it ;-) . So yes, I am one of those people who didn't stop to think about why I put it there, but I am sure I am not alone. And I am also sure there are many new perl programmers, who will make the same mistake. When will the madness end!!!!!!

Of course, in the interest of full disclosure, I'm the guy who submitted the patch that had the ref $proto || $proto code mostly removed from the latest perldocs.

Excellent! Did the patch get accepted?

-stvn


Comment on Re^2: Is "ref($class) || $class" a bad thing?
Re^3: Is "ref($class) || $class" a bad thing?
by Ovid (Cardinal) on Jul 12, 2004 at 16:49 UTC

    I don't expect programmers to automatically know they can call $object->new and if they try it without reading the docs then I would be in the "serves 'em right" camp. Does that do the same thing as calling new() on a classname (like all other class methods do?) or does it make a clone of the object? If it clones it, is it a deep or shallow copy? Do the two instances really share the same filehandle? There are just two many questions to be answered for something like that to not be documented.

    The patch for removing references to this from the perldocs was accepted with almost no disagreement. I was very surprised by that. Given how contentious the debate is, I was certain that more people on P5P would speak out against the patch.

    Cheers,
    Ovid

    New address of my CGI Course.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2014-08-31 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls