Much of this discussion is based on a misconception. Units and SI scale
factors
are very useful in software that describes or interacts with the real world,
but
primarily on input and output. They are not normally used for internal
calculations. The idea that one carries units on variables interior to
a program, and that those units are checked for all interior calculations, is
naive. Doing such thing adds unnecessary and often undesired complexity.
Rather, it is generally only desirable to allow users to include scale factors
and units on values they specify and values they read. This implies that it is
only necessary to provide a package for reading and writing physical
quantities,
and indeed such a package exists: QuantiPhy. QuantiPhy came out of the ideas
that were raised the last time this topic was discussed on this mailing list
a few years ago.
However, there are two reasons to consider adding both SI scale factors and
unit
in Python itself. First, SI scale factors have been an international standard
way of specifying real value for over 50 years, and use of SI scale factors
results in numbers that are more compact and easier to read than using
exponential notation. Second, providing units with numbers provides important
information, and specifying that information in a program reduces ambiguity,
and
providing the units results generally decreases the chance of errors. For
example, consider the following three versions of the same line of code:
virt /= 1048576
virt /= 1.048576e6
virt /= 1MiB
The last is the easiest to read and the least ambiguous.
Using the units and scale factor on the scaling constant results in an easy to
read line that makes it clear what is intended.
Notice that in this case the program does not use the specified units, rather
the act of specifying the units clarifies the programmers intent and reduces
the
chance of misunderstandings or error when the code is modified by later
programmers.
But this suggests that it is not necessary for Python to interpret the units.
The most it needs do is to save the units as an attribute so that it is
available if needed later.
-Ken
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/GLDH5XEUHOZHQRGTEAADDANQX67V3DZ2/
Code of Conduct: http://python.org/psf/codeofconduct/