in reply to Convenient Constructors - a Moo question

Personally I prefer the Attack->heavy approach over Attack->new("heavy"). Why? Because when (not "if"!) you mistype it as "haevy", then Perl will automatically generate an error message for you. You don't need to write that logic to check the string is valid; Perl will for you.

To an extent I agree with hippo's answer, that it's nice for constructors to be called new, but I don't think that warrants throwing out the whole approach. Instead you could just name the method Attack->new_heavy. This is perfectly clear, and similar to things like new_from_file or new_from_xml you see all the time.

Replies are listed 'Best First'.
Re^2: Convenient Constructors - a Moo question
by blindluke (Hermit) on Dec 06, 2014 at 21:29 UTC
    Instead you could just name the method Attack->new_heavy.

    Thank you, this seems like the perfect compromise. Wonderfully simple solution.

    - Luke