On Sun, 10 Apr 2022 at 18:44, Ronald Oussoren via Python-ideas
<python-ideas@python.org> wrote:
>
>
>
> On 8 Apr 2022, at 16:33, Steven D'Aprano <st...@pearwood.info> wrote:
>
> On Tue, Apr 05, 2022 at 02:17:00PM +1000, Chris Angelico wrote:
>
> Do you ever have one module that's using statute miles and
> another that's using nautical miles, but *not both in the same
> module*? The only reason to have them namespaced to modules is to
> allow different modules to use them independently. If your application
> needs to use both statute and nautical miles in the same module (most
> likely the main module), then it's going to have an issue, and your
> proposal adds a ton of complexity (that's a real unit, by the way, I
> totally didn't make it up) for no benefit whatsoever.
>
>
> That's not the real problem.
>
> The real problem is that my program may:
>
> * import ham, which registers mile as 1609.3412 m
> * import spam, which registers mile as 1609.344 m
> * import cheese, which registers mile as 1609.3472 m
> * import aardvark, which registers mile as 1609.3426 m
> * import hovercraft, which registers mile as 1853.181 m
>
>
> I’ve only scanned this thread and may have missed an explanation for this, 
> but why must there be a global registry?
>
> Explicit imports, possibly with a new dunder protocol for literal convertors 
> feels like a better fit to the language to me. This also avoids the problem 
> with a global registry you mention earlier.
>

That's precisely what Steven is arguing for, and I'm arguing against.
Primarily because YAGNI, but also for a more fundamental reason: the
registry of units is not simply a definition of name -> value, which a
namespace is capable of (but I think is wrong for this situation), but
it's also a definition of which units can be converted into which.
That would affect how two objects interact with each other - can you
add meters and miles? Can you treat the electron-volt as a unit of
mass? All these sorts of questions belong to the application, and
there's no useful way to divide them on module boundaries, much less
other scopes.

There's no point trying to make this scoped, just as we don't have
lots of other things scoped (like sys.modules). Shared state across
the application is a *good* thing, not a bad one.

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

Reply via email to