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

> > I'm unsure simple tags are enough. What should the behavior of this be?

>
> > height = 5ft + 4.5in
>
> My view on this is that it should basically be defined as:
>
> height = ft(5) + in(4.5)
>
> where you register your constructor functions (possibly types,
> possibly factory functions) using a hook in the sys module.
>

This is really similar to what pint does already (except it uses the
multiplication syntax if course).

What does that idea bring other than being able to say:

5.0m

(m registered in a previously run module)

.... instead of:

5.0*m

(m an object imported in a previously run module)

?

> Surely we ought to be able to add these values. But what should the
> resulting tag be? Should we be able to write it like this?
> >
> > height = 5ft 4.5in
>
> That, I would say, no. There are a lot of human-readable notations
> that aren't supported by programming languages, such as algebraic
> "abuttal means multiplication" and such. It's not that hard to say
> "5ft + 4.5in", just like you'd say "3 + 4j" for a complex number.
>

Makes sense to me.

(Also, I don't really see a lot of point in making feet-and-inches
> minorly less complicated, given that people should be trying to use
> metric anyway.)
>

They're almost all I use professionally. I graduated college in 2010 and
have almost never used centimeters or millimeters since then. "Shoulds"
aside, feet and inches are not going away and any unit system needs to make
them first class and easy to use or it will be extremely painful for large
chunks of progressional engineers.

But 5ft+4in is fine.

> I was cheerleading this effort earlier and I still think it would be a
> massive contribution to needs of the engineering world to solve this
> problem at the language level. But boy howdy is it a tough but of a problem
> to crack.
> >
>
> This is something where (again, my view only, others may disagree) the
> language itself need not actually make a decision. Ideally, the
> standard library should have something usable, but it should be such
> that you could choose to do something else. The standard library could
> even have more than one unit system in it - for instance, you could
> have a metric-focused system that converts "5ft" into "1.524m", or you
> could have a unit-retaining system that keeps everything in the unit
> specified until such time as conversions are needed, etc.
>

Yup, being able to choose to retain units or convert them to preferred
units is important.

One very important feature for the standard library would be a generic
> "Quantity" type, which could save a lot of hassle. You could create a
> "length" quantity and register a number of units, and define that any
> length can be added to any other length, a length can be multiplied by
> a scalar, etc, etc, etc. Then a bit of generic handling could also
> recognize that when you multiply or divide two quantities, you get
> something in a combined unit (whether that's "length*length" meaning
> area, or "length/time" meaning velocity), and libraries could slot in
> whatever units make the most sense. Maybe you're working with
> astronomical distances, and the meter just causes too many
> floating-point roundoff errors, so you define your base unit to be the
> parsec, and everything else derives from that. Or maybe you're working
> with video game analysis and the most important quantity is "items per
> minute" (eg 780 iron ore per minute), so you define each type of item
> as its own quantity, and redefine time with a basis of minutes instead
> of seconds. Having the tools to do that is probably more important
> than defining it all at the language level.
>

I like and think I understand most of what you're saying here. I think much
of this has been thought through and solved by the pint library, and some
others. Having a "slot" to natively associate a unit tag with numerical
values, and syntax support with defined semantics, could be a big win.
Leaving the "now let's make decisions about behavior" part to 3rd parties
makes sense to me.

But what superpower does bringing the notion of tagging things into the
native language bring for us if all the tag does is call a function that
returns a thing?

It almost just sounds like a postfix function call syntax to me.

>
_______________________________________________
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/CMIA6EN5QCEINLVNN2V2Y2K6FUQKBM3P/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to