module naming proposal: Number::Scale 
Author Message
 module naming proposal: Number::Scale

I have a small module that a couple of folks have asked me to post to CPAN,
and I'd like to get suggestions on an appropriate name. The module lets you
instantiate objects that will scale numbers and apply appropriate SI
prefixes. Simple example:

  use Number::Scale;
  my $converter = Number::Scale->new(
    unit    => 'byte',
    divisor => 1024,
    trunc   => 2
  );
  print $converter->scale(123_456_789);
  # '117.73 megabytes'

There's some other simple formatting that the object will do (like
singular/plural forms: "1 kilobyte" vs. "2 kilobytes"), but it's the scaling
and SI prefix application that is really the motivation here. So I'm
thinking that the name Number::Scale might be appropriate.

Thoughts, comments?



Fri, 19 Aug 2005 10:42:20 GMT  
 module naming proposal: Number::Scale

Quote:

> I have a small module that a couple of folks have asked me to post to CPAN,
> and I'd like to get suggestions on an appropriate name. The module lets you
> instantiate objects that will scale numbers and apply appropriate SI
> prefixes. Simple example:

[...]

Quote:
> Thoughts, comments?

Shooting from the hip ----

Which is more important, the scale or the SI?  Had you considered
Number::SI
Units::SI
Unit::SI

Does the scale part belong with the SI part, or can they be reasonably
factored into two modules that play well together?

--
Michael R. Wolf
    All mammals learn by playing!



Sat, 20 Aug 2005 01:10:14 GMT  
 module naming proposal: Number::Scale
Scaling and the SI prefix application are both tied together insofar as the
goal is to make numbers with units associated presentable in a more
human-friendly fashion. The typical application is where you are reporting
on some number whose values can span multiple orders of magnitude and would
like a nice way to package up the description, i.e.:

  $converter->scale(1);  # '1 byte'
  $converter->scale(2);  # '2 bytes'
  $converter->scale(1024);  # '1 KB'
  $converter->scale(7**8);  # '5.5 MB'

...instead of the usual "5764801 bytes" that you'd see in the last case.

So perhaps something like Number::PrettyUnits would describe that...

--John



Quote:

> > I have a small module that a couple of folks have asked me to post to
CPAN,
> > and I'd like to get suggestions on an appropriate name. The module lets
you
> > instantiate objects that will scale numbers and apply appropriate SI
> > prefixes. Simple example:

> [...]

> > Thoughts, comments?

> Shooting from the hip ----

> Which is more important, the scale or the SI?  Had you considered
> Number::SI
> Units::SI
> Unit::SI

> Does the scale part belong with the SI part, or can they be reasonably
> factored into two modules that play well together?

> --
> Michael R. Wolf
>     All mammals learn by playing!




Thu, 25 Aug 2005 01:37:31 GMT  
 module naming proposal: Number::Scale

Quote:

> Scaling and the SI prefix application are both tied together insofar
> as the goal is to make numbers with units associated presentable in a
> more human-friendly fashion.

Not necessarily.  Consider "Standard" units of distance (inches, feet
yards, miles), weight (ounces, pounds, tons), time, etc..  You might
want to give an amount in the smallest unit of these, and have them
scaled into a human-friendly format.  SI units are merely one type of
scaling.

Quote:
> The typical application is where you are reporting on some number
> whose values can span multiple orders of magnitude and would
> like a nice way to package up the description, i.e.:

>   $converter->scale(1);  # '1 byte'
>   $converter->scale(2);  # '2 bytes'
>   $converter->scale(1024);  # '1 KB'
>   $converter->scale(7**8);  # '5.5 MB'

I'd like to be able to do stuff like:

   use Number::Scale;
   my $basic_si = Number::Scale->SI;
   print $basic_si->scale(1024); '1 K'
   my $si_bytes = $basic_si->new(
      unit => ['byte', 'B'],
      trunc => 2,
   );
   print $si_bytes->(1024); # '1 KB'
   my $si_distance = $basic_si->new(
      unit => ['meter', 'M'],
      trunc => 2,
   );
   my $si_weight = $basic_si->new(
      unit => ['gram', 'G'],
      trunc => 2,
   );
   my $std_distance = Number::Scale->StandardDistance;
   print $std_distance->scale(25); # '2 feet 1 inch'
   my $std_weight = Number::Scale->StandardWeight;
   print $std_weight->scale(18); # '1 pound 2 ounces'





Thu, 25 Aug 2005 11:01:56 GMT  
 module naming proposal: Number::Scale

Quote:

> Scaling and the SI prefix application are both tied together insofar as the
> goal is to make numbers with units associated presentable in a more
> human-friendly fashion. The typical application is where you are reporting
> on some number whose values can span multiple orders of magnitude and would
> like a nice way to package up the description, i.e.:

>   $converter->scale(1);  # '1 byte'
>   $converter->scale(2);  # '2 bytes'
>   $converter->scale(1024);  # '1 KB'
>   $converter->scale(7**8);  # '5.5 MB'

> ...instead of the usual "5764801 bytes" that you'd see in the last case.

> So perhaps something like Number::PrettyUnits would describe that...

Yes, perhaps that's better.

I like "scale" or "prefix" better than "unit".  As a Physics major,
"unit" reminds me of "Unit of measure" which was meter, foot, gram,
amp, etc.  When someone asked me what units that measurement was in, I
could answer feet, inches, meters, or fathoms.

Byte is *not* an SI base unit, nor is it a derived one.  It is merely
another name for a thing like rock, or bird, and should be (IMHO)
separated from the scaling of the count.

If you'd like more information on SI units, look at the NIST site for
Constants, Units and Uncertainty

    http://physics.nist.gov/cuu/Units/
    http://physics.nist.gov/cuu/Units/units.html

Please don't invoke an international standard by name (i.e. SI) if you
aren't really implementing it.  To do so would cause a confusion for
your module users now, and in the future, and block the namespace for
someone who wanted to do so.

Here's a bit from the first page I referenced.  These *are* SI units.

Base quantity                   Name      Symbol
length                          meter     m
mass                            kilogram  kg
time                            second    s
electric current                ampere    A
thermodynamic temperature       kelvin    K
amount of substance             mole      mol
luminous intensity              candela   cd

The page goes on to talk about derivative units like velocity,
acceleration, area, volume.

And it discusses scaling, and newly minted binary multiple prefixes.
Perhaps that would be helpful to you.

http://physics.nist.gov/cuu/Units/prefixes.html
http://physics.nist.gov/cuu/Units/binary.html

Be careful.  By which I mean, please provide good documentation.  "M"
can mean 1,000 or 1024 in common usage.  I'd suggest that you provide
both, and have a different interface to them.  See the
"--human-readable" and "--si" argument to du(1) to note the
difference.  I'm sure other tools implement this numbering/naming.  If
you provide a useful module, it would be useful in the Perl world for
doing similar helpful output.  I'd love it if you did.  And it would
be nice to comma-ify the output, too.  I've cut the section of the
du(1) man(1) page here:

       -h, --human-readable
              print sizes in human readable format (e.g., 1K 234M 2G)

       -H, --si
              likewise, but use powers of 1000 not 1024

So again, I'm lead back to my original suggestion that units and
sacaling are separate problems, and would be served by *separate*
modules.

This whole thread reminds me of fun handout we got in Physics class.
I remember 2 of them.

2,000 mockingbirds   => two kilo mockingbird
10E-18 boy           => atto boy
...
more playfulness???

================================================================

Table 5.  SI prefixes
Factor Name  Symbol
10E+24 yotta Y
10E+21 zetta Z
10E+18 exa E
10E+15 peta P
10E+12 tera T
10E+9 giga G
10E+6 mega M
10E+3 kilo k
10E+2 hecto h
10E+1 deka da
10E-1 deci d
10E-2 centi c
10E-3 milli m
10E-6 micro
10E-9 nano n
10E-12 pico p
10E-15 femto f
10E-18 atto a
10E-21 zepto z
10E-24 yocto y

================================================================
Prefixes for binary multiples
 Factor  Name  Symbol  Origin Derivation  
 2**10 kibi Ki kilobinary: (2**10)**1 kilo: (10**3)**1
 2**20 mebi Mi megabinary: (2**10)**2 mega: (10**3)**2
 2**30 gibi Gi gigabinary: (2**10)**3 giga: (10**3)**3
 2**40 tebi Ti terabinary: (2**10)**4 tera: (10**3)**4
 2**50 pebi Pi petabinary: (2**10)**5 peta: (10**3)**5
 2**60 exbi Ei exabinary:  (2**10)**6 exa:  (10**3)**6

Examples and comparisons with SI prefixes
one kibibit  1 Kibit = 210 bit = 1024 bit
one kilobit  1 kbit = 103 bit = 1000 bit
one mebibyte  1 MiB = 220 B = 1 048 576 B
one megabyte  1 MB = 106 B = 1 000 000 B
one gibibyte  1 GiB = 230 B = 1 073 741 824 B
one gigabyte  1 GB = 109 B = 1 000 000 000 B

I like the idea.  I think it would be *very* helpful.  I really don't
like seeing lists of long numbers.  This module would go a long way to
helping folks make better output.  But it's got the possibility of
being confusing, so I offered my feedback.

Hope this is taken in the spirit it was offerred -- helpfulness.  

Michael Wolf

Quote:

> --John




> > > I have a small module that a couple of folks have asked me to post to
> CPAN,
> > > and I'd like to get suggestions on an appropriate name. The module lets
> you
> > > instantiate objects that will scale numbers and apply appropriate SI
> > > prefixes. Simple example:

> > [...]

> > > Thoughts, comments?

> > Shooting from the hip ----

> > Which is more important, the scale or the SI?  Had you considered
> > Number::SI
> > Units::SI
> > Unit::SI

> > Does the scale part belong with the SI part, or can they be reasonably
> > factored into two modules that play well together?

> > --
> > Michael R. Wolf
> >     All mammals learn by playing!


--
Michael R. Wolf
    All mammals learn by playing!



Fri, 26 Aug 2005 13:41:25 GMT  
 module naming proposal: Number::Scale


Subject: Re: module naming proposal: Number::Scale



Gcc: nnfolder+archive:mail.2003-03
--text follows this line--

Quote:


> > Scaling and the SI prefix application are both tied together insofar
> > as the goal is to make numbers with units associated presentable in a
> > more human-friendly fashion.

> Not necessarily.  Consider "Standard" units of distance (inches, feet
> yards, miles), weight (ounces, pounds, tons), time, etc..  You might
> want to give an amount in the smallest unit of these, and have them
> scaled into a human-friendly format.  SI units are merely one type of
> scaling.

> > The typical application is where you are reporting on some number
> > whose values can span multiple orders of magnitude and would
> > like a nice way to package up the description, i.e.:

> >   $converter->scale(1);  # '1 byte'
> >   $converter->scale(2);  # '2 bytes'
> >   $converter->scale(1024);  # '1 KB'
> >   $converter->scale(7**8);  # '5.5 MB'

> I'd like to be able to do stuff like:

>    use Number::Scale;
>    my $basic_si = Number::Scale->SI;
>    print $basic_si->scale(1024); '1 K'
>    my $si_bytes = $basic_si->new(
>       unit => ['byte', 'B'],
>       trunc => 2,
>    );
>    print $si_bytes->(1024); # '1 KB'
>    my $si_distance = $basic_si->new(
>       unit => ['meter', 'M'],
>       trunc => 2,
>    );
>    my $si_weight = $basic_si->new(
>       unit => ['gram', 'G'],
>       trunc => 2,
>    );
>    my $std_distance = Number::Scale->StandardDistance;

Or...

     my $std_distance = Number::Scale->StandardDistance('English');
     print $std_distance->scale(25); # '2 feet 1 inch'

     my $si_distance = Number::Scale->StandardDistance('SI');
     my $si_distance = Number::Scale->StandardDistance();
     print $si_distance->scale(25); # 0.333-ish meter

My suggestion would be to honor the international standard, the meter,
and the historical anomoly, the foot, with separate arguments to a
scaler[1] constructor.  I'd propose that no argument is the same as
'SI', and that 'english' would have to be supplied to get the
degenerate case (the one we use in the U.S., and the one that I'm
familiar with by birth, though I'm kind familiar with SI units through
Physics and international discourse).

[1] Note 'scaler' is something that scales, not a misspelling of
'scalar'.

Quote:
>    my $std_weight = Number::Scale->StandardWeight;
>    print $std_weight->scale(18); # '1 pound 2 ounces'

                                   # 0.5-ish kilograms
                                   # 500-ish grams

--
Michael R. Wolf
    All mammals learn by playing!



Fri, 26 Aug 2005 13:50:19 GMT  
 module naming proposal: Number::Scale


Quote:
> 'SI', and that 'english' would have to be supplied to get the
> degenerate case (the one we use in the U.S., and the one that I'm
> familiar with by birth, though I'm kind familiar with SI units through
> Physics and international discourse).

As I read it you don't mean 'english' but maybe 'Imperial' measure,
which is what it's known as in the United Kingdom[1], or possibly
Avoirdupois for weight measure. The original poster is lost in the mists
of my newsreader's "you've read that" list, but whoever it was I'd say
that they should make every effort to get the names of systems of
measure correct and allow for expansion, and that their conversion
factors are correct to a good number of decimal places. I'll see if I
can suggest anything in that respect :-) The perl side of things looks
OK though.

P

[1] as well as informal names such as 'old money', 'real money', 'proper
units' and the like :-)

--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply



Sat, 27 Aug 2005 09:20:04 GMT  
 module naming proposal: Number::Scale

Quote:



> > 'SI', and that 'english' would have to be supplied to get the
> > degenerate case (the one we use in the U.S., and the one that I'm
> > familiar with by birth, though I'm kind familiar with SI units through
> > Physics and international discourse).

> As I read it you don't mean 'english' but maybe 'Imperial' measure,
> which is what it's known as in the United Kingdom[1], or possibly
> Avoirdupois for weight measure.

Hear, hear!!!

--
Michael R. Wolf
    All mammals learn by playing!



Sat, 27 Aug 2005 12:39:36 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. module naming proposal: Text::Messages

2. 2 module proposals Text::Number, Math::Financial

3. proposal for name parsing module

4. module proposal proposal Text::RandomQuip

5. Scale -- odd numbers only?

6. Canvas->Scale and Tk::Scale conflict?

7. PROPOSAL: GraphViz::XMLObjects (tentative name)

8. Name space proposal Image::Button

9. Name space proposal String::Thai::Segmentation

10. Proposal and prototype of named parameter lists and other features

11. New module proposal: NetServer::Generic

12. new module proposal: I18N::Charset

 

 
Powered by phpBB® Forum Software