Number::Fraction

Dave Cross dave at dave.org.uk
Fri May 3 09:21:19 BST 2013


Quoting "Th. J. van Hoesel" <th.j.v.hoesel at gmail.com>:

> to me, it would make sense for 3 parameters:
>
> Number::Fraction->(int, num, den);
>
> but that would be helpful to work with the so called vulgar  
> fractions and cold write things like:
> my $twothreefourth = Number::Fraction->new( 2, 3, 4);

I think we're starting to get quite close to an area where positional  
parameters are potentially confusing.

   Number::Fraction->new(1, 2); # num = 1, den = 2
   Number::Fraction->new(1, 2, 3) # int = 1, num = 2, den = 3

I would probably think seriously about using named parameters here

   Number::Fraction->new(numerator => 1, denominator => 2);
   Number::Fraction->new(integer => 1, numerator => 2, denominator => 3);

Of course, the fact that the names of the parameters are so long  
really counts against you here, so you'd want to allow aliases - int,  
den & num.

In fact, it probably makes sense to move it all to Moose (or Moo, at least).

> can I drop other cases or do you prefer to allow method calls with  
> unlimited number of parameters ???

You need to deal with idiots who ignore the documentation and call the  
methods with the incorrect parameters. Currently, if you call new()  
with more than two parameters, the extra ones are just silently  
ignored. I think I like that option best, but I wouldn't object if the  
constructor just died instead.

Cheers,

Dave...

p.s. This conversation would be much easier to follow if we all used  
the same quoting style :-/



More information about the london.pm mailing list