On Wed, Apr 6, 2022 at 5:11 AM Oscar Benjamin <oscar.j.benja...@gmail.com>
wrote:

> > >Personally I think giving Decimal a global context was a mistake, [...]
>

I agree here -- though honestly, I think the benefits of Decimal are often
misrepresented. Interestingly, the variable precision is the real bonus,
not the decimal representation.

Anyhoo ...


> > I'd be curious to know what alternatives you see. When a user writes `x
> + y` with both `x` and `y` instances of `decimal.Decimal`, the decimal
> module needs to know what precision to compute the result to


What do other variable precision systems do? With a quick read, it looks
like gmpy2 does something similar :-(


> (as well as what rounding mode to use, etc.). Absent a thread-local
> context or task-local context, where would that precision information come
> from?
>

Why is that absent? -- it seems a task local and/or thread local context is
exactly what should be done.


> One possibility is to attach the context information to the instances
> so it's like:
>

That seems the obvious thing to me -- a lot more like we already have with
mixing integers and floats, and/or mixing different precision floats in
other languages (and numpy).

Different, as this wouldn't be type based, but if clear rules are
established, then it would be do-able. At least it would probably fit the
maxim:

The easy stuff should be easy, the hard stuff should be possible.

Perhaps even something as simple as "Preserve the precision of the highest
precision operand" would go a long way.

Realistically do many users want to use many different contexts and
> regularly switch between them? I expect the common use case is wanting
> to do everything in a particular context that just isn't the default
> one.
>

I don't know that that's true in the least -- sure, for a basic script,
absolutely, but PYthon has become a large ecosystem of third party
packages -- people make a LOT of large systems involving many complex third
party packages -- the builder of the system may not even know a package is
using Decimals -- let alone two different third party packages using them
in very different ways -- it's literally impossible for the developer of
package A to know how package B works or that someone might be using both.

Then put all this behind a multithreading web server, and you have a recipe
for chaos.

-CHB


-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
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/ATPMR4OCIDPQ2BI5DMVAQKZZHG3AINUU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to