good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
$class = ref $class || $classby rir (Vicar) |
on Feb 26, 2003 at 21:58 UTC ( [id://238931]=note: print w/replies, xml ) | Need Help?? |
I've never considered $foo->new() to indicate cloning,
but rather a better looking way to say (ref $foo)->new().
I accept the $class = ref $class || $class as a Perl-specific idiom and so don't find it confusing. It is a bad idiom though. In itself it reads as nonsense: class is the ref of class or class. Worse is the habit that you have acquired: to think that $foo->new; is shorthand for (ref $foo)->new;. This is bad because they don't mean the same thing unless you know the internals of new. Also if you don't know the type of $foo you should explicate this fact with ref $foo not leave the issue in doubt. As this use is idiomatic Perl it is not too confusing once you realize a codebase uses the idiom. However it is sloppy, it spreads in a codebase and is some work to undo. I write something inside my new (for no reason) that allows you to imply different meanings (for no reason) through the different usages that I allowed (for no reason). Sloppy. It buys nothing. It will give pause to the better OO programmers who are new to Perl.
In Section
Meditations
|
|