While units are certainly useful, I think this is FAR too large to add to
Python syntax. A library like "units" is great, but it really needs to be a
library, and not a small one.

There are thousands of units in use in sciences, commerce, engineering,
ordinary life, etc. In all of them, it is not uncommon for the same few
letters to represent multiple things, depending on context.

But as well as the sheer number, what is convertible to what, and in what
context, is very nuanced.

An electron volt is a unit of energy. Or of mass. Or of momentum. It's
usual to convert among these meanings for these units. But bordering on
nonsense to convert among kilowatt-hours and grams. It depends on the
practical context of units.

Even in Ethan's example, he uses kilogram as a unit of weight. It answers a
question with the word weight in it (albeit 300 kg is extreme for a human
weight, maybe for brick pallets). But kg IS NOT a unit of weight. It's a
unit of mass. In the context of thing on the surface of the earth near the
same elevation, we might convert between kg and lbs. But in other contexts
it makes no sense.

I'm older than 35 (Earth) years, but my age is also counted differently
according to different calendars and cultural conventions.  Of his
examples, °F is the only one that is completely convertible to other
temperature scales, but even there, it's rare to see a bread recipe in
degrees Kelvin.

Units like time intervals and currencies are EXCEEDINGLY complicated. The
conversion rate between Dirham and USD fluctuates by microsecond, but can
also have two simultaneous values on different exchanges. At the least, a
unit of currency has built into it an absolute time, but also often a
relative time to a specific refence time.

... So then we get to the point of saying "don't do any of that, just
annotate the number with an arbitrary string/object." Which sure, is
possible. Not even difficult. But we can also do it already without syntax
by subclassing int, or float, or complex, or Decimal, or Fraction. Or we
can do it just with name conventions too.  Perhaps 'person_kg' is just a
numeric variable reminding us of its unit.

On Sun, Apr 3, 2022, 6:25 PM Chris Angelico <ros...@gmail.com> wrote:

> On Mon, 4 Apr 2022 at 07:45, Ethan Furman <et...@stoneleaf.us> wrote:
> > Mechanically, are `lbs`, `km`, `hr`, etc., something that is imported,
> or are they tags attached to the numbers?  If
> > attached to the numbers, memory size would increase and performance
> might decrease -- but, how often do we have a number
> > that is truly without a unit?
> >
> > How old are you?  35 years
> > How much do you weigh?  300 kg
> > What temperature do you cook bread at?  350 F
> >
>
> Very frequently - it'd be called an index. (What sort of numbers
> should enumerate() return, for instance? Clearly that, whatever it is,
> is an index.) But if every int and float has a tag attached to it,
> it's not that big a deal to have either a default tag, or leave the
> field NULL or None, to define it to be a unitless value or index.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/7LTKMLQFJHQYU2TGQCPYBXXX6472M3H7/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JO2IBCSMVUOX34IL3NJWWPF64RLBYVFY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to