prePEP: Decimal data type

John Roth newsgroups at jhrothjr.com
Thu Nov 6 15:07:22 EST 2003


"Tim Peters" <tim.one at comcast.net> wrote in message
news:mailman.487.1068133912.702.python-list at python.org...
> [Aahz]
> > Well, sure.  And it won't be hard to add given that Decimal will
> > already need to track thread-specific Context.  But modules changing
> > Context will still need to explicitly push and pop Context because
> > usually you will just want to replace the current Context.
>
> They have another choice, because Guido had a brilliant idea:  the
> arithmetic operations in Eric's implementation are methods *of* a context
> object (because Guido suggested that).  So a maximally robust library
> doesn't *have* to change the thread context at all:  it can create
whatever
> private context object(s) it needs, and spell arithmetic as explicit
method
> calls on its private context object(s), so that the default thread context
> object is neither consulted nor modified.  This is very robust, and in
small
> doses is quite bearable.

I think I agree: Guido committed a brilliancy there. Having had to deal
with monetary calculations and the weird rounding mandated by various
laws, regulations and way out of it PHB accountants, I don't see how
simple expression syntax is ever going to do what is needed.

AFAICS, there are only two solutions:

<decimal>.add(<number>, [<result spec>])

and

<context>.add(<decimal>, <number>)

The difference is in where you put the various factors.

I think they both come out to roughly the same number of
keystrokes, especially if you assume that <result spec> can
be a variety of different things, including a full blown context
object.

John Roth

>
>






More information about the Python-list mailing list