in reply to Re^6: RFC: Tool::Box
in thread RFC: Tool::Box

I was thinking about this. If I wanted to maintain a running average or running list of unique items (ordered or not) ... I'm probably designing my program around it. Therefore, setting some flag is probably ok with me. What would be wrong with:
use Tool::Box qw( :running_totals )

That was, you provide normal functions as the default (with $ave returning undef or 0 in your example above). But, if someone wants the cool running-totals feature, they can turn it on.

Another possibility would be to provide Tool::Box and Tool::Box::Running_Total. *shrug* I'm just brainstorming here ...

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^8: RFC: Tool::Box
by diotalevi (Canon) on Nov 22, 2004 at 15:10 UTC

    This is a horrible idea. This means I can't read Tool::Box::func( LIST ) and can't know from reading the function name whether it returns the function-appropriate result or an accumulator function. It also means that once I've understood that I'm going to get an average (or whatever), that if I read the function name somewhere else, it doesn't necessarilly mean the same thing.

    The function in different modes must have different names. You're just making obfuscated code otherwise.

Re^8: RFC: Tool::Box
by Limbic~Region (Chancellor) on Nov 22, 2004 at 14:56 UTC
    dragonchild,
    I like this idea. Basically say there are three modes
    • The subs work normally :default
    • The subs return functions :functional
    • Mix and match :hybrid
    Of course, there would be no need to specify :default. Then a note with :hybrid concerning unintentional behavior WRT empty lists. If you want both at the same time then you need to be prepared for unexpected results.

    Cheers - L~R