type-checking support in Python?

Lorenzo Gatti gatti at dsdata.it
Tue Oct 7 03:25:40 EDT 2008


On 7 Ott, 08:36, Lawrence D'Oliveiro <l... at geek-
central.gen.new_zealand> wrote:
> In message <mailman.2089.1223358567.3487.python-l... at python.org>, Gabriel
>
> Genellina wrote:
> > As an example, in the oil industry here in my country there is a mix of
> > measurement units in common usage. Depth is measured in meters, but pump
> > stroke in inches; loads in lbs but pressures in kg/cm².
>
> Isn't the right way to handle that to attach dimensions to each number?

Can you afford to avoid floats and ints? Attaching suffixes is the
best one can do with the builtin types.
In C++ one can check dimensions at compile time (http://www.boost.org/
doc/libs/1_36_0/doc/html/boost_units.html) with a modest increase of
cumbersomeness, but Python would need very heavyweight classes
containing a value and its dimension and a replacement of all needed
functions and operations.

Regards,
Lorenzo Gatti



More information about the Python-list mailing list