Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Re (tilly) 2: Paradigm Shift - Dual Use Constructors

by Matts (Deacon)
on Feb 20, 2002 at 08:01 UTC ( #146519=note: print w/ replies, xml ) Need Help??


in reply to Re: Re (tilly) 2: Paradigm Shift - Dual Use Constructors
in thread Paradigm Shift - Don't use strict

When I call GA::Entity->new() it returns a randomly generated solution. When I call $ga_entity->new() it produces a randomly mutated version of $ga_entity, and when I call $ga_entity->new($other_ga_entity) it returns a cross of the two. I thought long and hard if I wanted this type of behaviour and experimented with a number of alternatives before deciding I was happy with this approach. But of course merlyn would mark me down bigtime without considering why I had done it, and what my reasons were.

I fail to see how someone would mark you down on this, because you wouldn't have the traditional my $class = ref($proto) || $proto, you would have something much more complex wrapped around:

if (ref($proto)) { if (ref($_[0])) { cross polinate } else { mutate } } else { construct new }
Which would look far more reasonable in a code review, and would almost inevitably have to be documented. So I don't buy your argument.


Comment on Re: Re: Re (tilly) 2: Paradigm Shift - Dual Use Constructors
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Re: Re (tilly) 2: Paradigm Shift - Dual Use Constructors
by demerphq (Chancellor) on Feb 20, 2002 at 09:59 UTC
    Hmm. Interesting angle. But ircc (its on my home computer) the code went more like
    sub new { my $proto=shift; my $class=$proto || ref $proto; my $self=bless {},$class; if ($class eq $proto) { #class call $self->init_rand(); } elsif (@_) { $self->init_cross($proto,shift); } else { $self->init_mutate($proto); } return $self }
    So the dreaded line was/is present. But you are correct I did/would comment this.

    Yves / DeMerphq
    --
    When to use Prototypes?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2015-07-31 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls