Boost logo

Boost :

From: Deane Yang (deane_yang_at_[hidden])
Date: 2005-10-11 11:40:29


Matt Calabrese wrote:

> On 10/11/05, Deane Yang <deane_yang_at_[hidden]> wrote:
>> Although I appreciate your efforts to implement an efficient way to
>> automatically convert different units for the same quantity, I would
>> still prefer a library that requires an explicit "cast" to change units,
>> rather than implicit. Perhaps the library could be built in two layers,
>> with the lower level requiring explicit casts and a layer above that
>> that implements implicit casting for those who want it.
>
>
> When I first started with the library, I thought that might be a good idea,
> but as development went on I decided that it wasn't really necessary. Could
> you actually give any example as to why you would actually want such
> restrictions? Keep in mind that explicit unit casts are still available.
>

I work mostly with calendar time. Although I want to view both years and
months as units for the same vector quantity (time duration), I find
that in any one code module, I always want to use a single consistent
unit (which might be templatized). All the unit casting occurs only for
inputs and outputs to the module. So if my code tries to add years to
months, it's a coding error.

I can't speak for the people programming in physical units, but I just
can't imagine wanting to mix variables representing the same dimension
with different units in a single arithmetic expression. Even with a
dimensions library, it seems like a recipe for trouble to me. To me it's
much safer to convert all inputs (which may have different units) into a
single set of consistent units when entering a module and converting all
outputs into the desired units when exiting. By using templates, this
can all be done very cleanly without hardwiring either the internal
units or the external units.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk