On 02/11/2014 12:13 AM, shawn wilson wrote:
On Mon, Feb 10, 2014 at 11:50 PM, Uri Guttman <u...@stemsystems.com> wrote:

sub new
{
    my ($proto) = @_;
    my $class = ref($proto) || $proto;


don't do that style of getting the class. it is meant to handle class or
object method calls and is considered poor design.


So, I guess the question is, why? I'll read a blog or other reference
if that's easiest.

new() should be a class method that only gets the class passed to it. if you want object methods to create new objects, call them clone or similar. they are different concepts, creating a new object or creating one from an existing object. usually clone will also initialize the new object from the old one. that is a very different thing than just creating a new object.

so that idiom has been around for a long time and isn't needed in most cases. you don't see it much in new code and it usually marks cargo cult copying of an idiom with no real reason behind it. did you expect to call your new() with an object vs a class name? if not, then you don't need that code.

uri

--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to