On 2016-08-26 07:54, Steven D'Aprano wrote:
[snip]
Specialist applications might be able to take shortcuts in
dimensional analysis when "everybody knows" what the suppressed units
must be. General purpose programming languages *cannot*. It is better
NOT to offer the illusion of dimensional analysis than to mislead the
user into thinking they are covered when they are not.

Better to let them use a dedicated units package, not build a
half-baked bug magnet into the language syntax.

If you're going to have units, you might also include (for want of a
name) "colours" (or "flavours"), which behave slightly differently with
respect to arithmetic operators.

For example:

When you add 2 values, they must have the same units and same colours. The result will have the same units and colours.

    # "amp" is a unit, "current" is a colour.
    # The result is a current measured in amps.
    1 amp current + 2 amp current == 3 amp current

When you divide 2 values, they could have the same or different units, but must have the same colours. The result will have a combination of the units (some might also cancel out), but will have the same colours.

    # "amp" is a unit, "current" is a colour.
    # The result is a ratio of currents.
    6 amp current / 2 amp current == 3 current
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to