Rhesa Rozendaal writes:

> Smylers wrote:
> 
> >   my %opts = (countername => $countername, @_);
> [...]
> >   bless \%opts, $pkg;
> > 
> > But supplying the default values for each individual option means
> > this technique doesn't avoid having a line listing each option -- it
> > just saves having to mention the keyname twice on each line -- so
> > may not be worth doing.
> 
> That's one reason; the other is that the way I do it now doesn't
> introduce unwanted data in my object. Any unknown key-value pairs are
> silently discarded.

I considered that, and decided it didn't matter.  Theoretically people
shouldn't pass unknown named params to your method; it's undefined what
happens if they do, so I wouldn't worry about it (your way ignores them
straight away; my way stores them in the object for ignoring later, but
the end result is pretty much the same) and just do whatever seems
simpler.  

(Arguably silently ignoring them is not the best thing to do -- the
user's done something pointless, probably a typo or a misunderstanding,
and it might be helpful to tell them, and perhaps using something like
Params::Validate would be better than either way.)

Question: Consider the point of view of the author of a module that
subclasses your module; such a module could well add further named
params for its additional functionality -- is it more useful for the
constructor in the superclass to store 'unknown' named params in the
object or not?  (I can think of arguments either way, and I'm feeling
too lazy today to work out which I'd prefer.)

> But I'm thrilled that a class with only four methods and very little
> functionality can generate this discussion. I really like this :) ...
> You've made me aware of a number of shortcomings that I hadn't given
> much thought.  But most importantly, you've given me the confidence
> that it's quite doable, though by no means trivial, to put a good
> package together.  And I very much enjoyed our conversation too :-)

Good!  I've enjoyed it too -- you've asked questions very politely, and
you've given good consideration to suggestions, that I'd've felt it rude
for me not to put the effort in and examine your code!  I think this is
what open source is _supposed_ to feel like!

Smylers
-- 
May God bless us with enough foolishness to believe that we can make a
difference in this world, so that we can do what others claim cannot be done.

Reply via email to