On 8/23/06, Kevin Olbrich <devlists-ruby-talk / devlists.com> wrote:
> Hey, amazing all the interesting stuff that pops up when you know where
> to look for it.
>
> After a 15 minute look, I can see some issues with the current version
> of Units in facets.
>
> 1. It doesn't implement Comparable.
>    1.cm < 2.m  #=> throws an exception in Facets
>    "1 cm".unit < "2 m".unit  #=> returns true in ruby-units
>
> 2. The binary prefixes are incorrect (at least in the RDoc).  They
> should be like 'kibi = 2**10' and 'mebi = 2**20'.

I have no problem adding these. However, personally, I don't like
kibibyte and prefer kilobyte, and I expect I'm not alone. Facets'
units.rb is flexible enough to allow kibi = 2**10 and kilo = 10**3
(following the IEC convention,
http://en.wikipedia.org/wiki/Binary_prefix) next to kilo = 2**10. The
only issue is which to make the default.

> 3. Facet Units doesn't seem to do temperature conversions.  Maybe it
> does, but I can't find any documentation on it.

It doesn't as temperature conversions are ill-defined. As you know,
both absolute temperatures and temperature differences have the same
unit. Any operation on two temperatures expressed in different units
cannot be correct for absolute temperatures and temperature
differences. This is an inherent problem, so we had three choices: do
no conversions, use the conversion for absolute temperatures, or use
the conversion for temperature differences. We chose the first of
these three. We're open to additional ideas on this.

> 4. I haven't found a simple way to convert a string into a Unit using
> Facets.  One reason that ruby-units does this is because I wanted to
> make it easy for users to provide units as input and then parse them.
> The facets Units seem to work fine if you know which units you want to
> use when you write your program.

I remember implementing this, so it should be present in the version I
sent Trans.

> 5. ruby-units is much more flexible in terms of what units it recognizes
> with the default configuration.
>   1.attoparsec/microfortnight.to(inch/s)  # => fails in Facets
>   "1 attoparsec/microfortnight".unit("in/s") #=> "1.0043269330917 in/s"
> in ruby-units
>
> 6. Facets seems to get in trouble when the name of a unit collides with
> a ruby keyword
>   1.m.to(in) #=> causes a parse error in Facets
>   This isn't an issue in ruby-units since all the units are specified as
> strings.

This is indeed a bit of a problem. Again, if I remember correctly, the
new version should handle strings as well, though maybe/probably not
for every operation.

> 7. ruby-units does not do dynamic currency conversions right now.
>
> 8. Facet Units does not seem to implement may Numeric methods like (abs,
> ceil, floor, to_i, round, etc..).  This works as you would expect with
> ruby-units.
>
> 9. Facet Units seems to be unable to simplify units in some cases..
>    (1.m * 1.m) / (1.cm * 1.cm) #=> 1 m**2/cm**2
>    I can't figure out how to convert this result to a float.
>
>    In ruby-units, the equivalent would be.
>    ("1 m".unit * "1 m".unit / ("1 cm".unit * "1 cm".unit)).to_base.to_f
> #=> 10000.0

I remember that this is by design, although I don't remember the
actual reason behind this design decision. I think it was because this
automatic conversion may be unwanted because the conversion introduces
rounding errors in some cases, and it is better to postpone the
conversion until the programmer explicitly requests this. This is done
using #to, but that doesn't work for unitless quantities as in your
example above (unless you do .to(m/m) or so), so we need a to_f method
indeed.

> Disclaimer:  Some of these observations may be erroneous due to my
> unfamiliarity with this package.  Feel free to correct them.

I have a disclaimer of my own: it is not a finished library, and all
of the issues above that I haven't addressed were planned to be added
at some point. I have been focussing my attention on getting the base
functionality right. Your observations above shouldn't be hard to add.

> I'd be happy to work with Facets to improve it's handling of units.

I'll work on addressing your observations above this evening, and I'll
send the new code to Trans and you. Thanks for your interest, and your
help.

Peter