[Python-Dev] Decimal.py in sandbox

Mike Rovner mike at nospam.com
Wed Oct 29 16:45:03 EST 2003


Aahz wrote:
> In article <mailman.211.1067451069.702.python-list at python.org>,
> Mike Rovner <mike at bindkey.com> wrote:
>>
>> Why 5+3. -> 8. ok,
>> but Decimal(5)+3 -> 8. is not ok?
>>
>> I favor implicit conversion as long as first stays true.  It's fast
>> (no decimal arithmetic), it's understandable, it's in line with other
>> numeric.
>
> The problem is that the vast majority of people who use Decimal want
> accuracy.  Decimal(5)+1.1 does not have an accurate answer.

In that case they shall not use float at all. '1.1' is not accurate per se.

> Remind yourself of this gems from The Python Way:
>
> Explicit is better than implicit.

I understand that case as explicit (same way as in case 1: 2+3.):
explicit use of float makes all float.

> Errors should never pass silently.

'Decimal' people might treat that as error, but I think Python is more
general.
'Normal' people don't treat mathematical expression 2/3 + 0.5 as an error.

IMHO it follow standard 'downgrading' practice: if you have more accurate
and less accurate,
treat result as less accurate.

BTW. Can I overload Decimal.__coerce__ to catch attempt to coerce it to
float?
If yes, that 'decimal' application can forbid it and be on the safe side.

> In the face of ambiguity, refuse the temptation to guess.

That's right, ergo never ever produce Decimal from float implicitly.

Mike








More information about the Python-list mailing list