in reply to Correct idiom for default parameters

Test::new() is pretty un-Perl/OO way to get an object made. Object constructors are generally called as class or objects methods: Test->new([args]). Then you'd have an _init methods to process the args to new or later in other calls where they are allowed. I hope you are not really using the name "Test" for your package. :)

I find >2 arguments to be the tipping point for making named arguments much preferable to positional. What MidLifeXis showed is a good way to go about that.

Replies are listed 'Best First'.
Re^2: Correct idiom for default parameters
by mrider (Beadle) on Apr 28, 2010 at 18:33 UTC

    Good points. Understand though, that this bears almost no resemblance to my "real" code. I was attempting to put together the absolute minimum necessary to demonstrate the question and my intentions. And no, my real package isn't called "Test" :)

    For the most part, the sub routines in question take one parameter and it's optional. I think there's one (maybe two) subroutines that take two where the first is mandatory, and the second is optional. I'd have to look again, as I forget off the top of my head. I do appreciate the input though.

Re^2: Correct idiom for default parameters
by JavaFan (Canon) on Apr 29, 2010 at 09:45 UTC
    Object constructors are generally called as class or objects methods Test->new([args])
    There's only one object constructor in Perl, and it's called bless. Test->new is nothing more than a class method, that just happens to return an object, often of the same class. More often than not, programmers decide said new() creates a brand-spanking new object, which gets initialized as well. These programmers make it hard to do MI.

      I know. I was guessing that was understood though perhaps being so explicit would have been helpful here for the OP.

      I don't understand ...

      Imho it's common and accepted terminology to call methods returning member objects "constructors"

      --lanx

        Accepted terminology is irrelevant when you're picking nits
        That terminology dates from the same time people thought hashref based objects were great. Just because people repeat others doesn't make them right. Or not use confusing terminology. If new is an object constructor, then what does bless create? Santa Claus?