in reply to Re4: Constructor/Factory Orthodoxy
in thread Constructor/Factory Orthodoxy
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $class = ref $class || $class
by herveus (Prior) on Feb 27, 2003 at 20:16 UTC | |
by rir (Vicar) on Feb 27, 2003 at 21:56 UTC | |
by herveus (Prior) on Feb 28, 2003 at 13:06 UTC | |
by rir (Vicar) on Feb 28, 2003 at 15:52 UTC | |
by herveus (Prior) on Feb 28, 2003 at 17:13 UTC | |
| |
by Abigail-II (Bishop) on Feb 28, 2003 at 13:24 UTC |