[Python-ideas] Python Numbers as Human Concept Decimal System

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Mar 11 18:03:01 CET 2014


On 11 March 2014 15:45, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Le 11/03/2014 16:26, Paul Moore a écrit :
>
>>
>> It feels to me as if what we're discovering here is why dynamic
>> scoping is a bad thing. If context was lexically scoped, all of this
>> concern about "action at a distance" and user code impacting library
>> behaviour would go away.
>
>
> I don't think that's the problem. What you call "dynamic scoping" is a
> feature here,

I think it would more appropriately be called "global scoping" but yes
it is a feature when used carefully.

> and "lexical scoping" wouldn't solve the issue: simply, the
> parser and compiler run before executing any Python code, so they can't see
> any changes in decimal precision triggered by a library call.

The issue is bigger than constant folding. The problem is about being
able to understand a simple looking expression or block of code. With
the decimal module it becomes necessary to consider many different
cases. What if the precision is less than X or higher than Y? What if
this particular Decimal has a precision exceeding that of the current
context? (The extra precision is not ignored; rounding effectively
occurs *after* each calculation.)

The issue applies to all programmers but consider the case where an
inexperienced user posts code that doesn't work asking for help. On
the one hand you don't know if they've modified the context and can't
be sure that you understand what the code does. On the other hand you
don't want to have to bombard them with technical details about
whether the context was modified or explain how to check if they're
unsure.


Oscar


More information about the Python-ideas mailing list