[Python-ideas] PEP 3150 (statement local namespaces) updated based on April discussion

Terry Reedy tjreedy at udel.edu
Mon Jun 13 22:09:18 CEST 2011


On 6/13/2011 12:59 PM, geremy condra wrote:
> On Sun, Jun 12, 2011 at 2:20 PM, Terry Reedy<tjreedy at udel.edu>  wrote:

>> 'Given' or 'where' constructs are sometimes used in mathematical writings,
>> especially formula exposition, but they typically, if not always, are
>> isolated (like the examples in the PEP), and not part of a code sequence. So
>> this is notreally a precedent to me. Example:
>>
>>   fv = p * (1 + i/12)**t... , where
>>     fv = present value
>>     p  = principle
>>     i  = nominal annual interest rate
>>     t  = time in months
>>
>> -(1+whatever)
>
> I've historically been in favor of this kind of proposal specifically
> because I'd like to be able to write the above code,

Part of my point is that the above is not *code* (and hence not an 
argument for formatting code that way). It is a text definition. Someone 
who wrote something like the above might very well then write a *code* 
version the equivalent of

p = input("principle: ")
i = input("nominal annual interest rate: ")
t = input("time in months: ")
print("Future value of ${} at {}% after {} months is ${}"
       .format(p, i, t, p*(1+i/12)**t

 > but I have to
> admit that many of the examples given in the PEP terrify me. The point
> of exposition like this is to enhance readability by making the flow
> of information (defined by the equation on the first line) extremely
> clear; tucking functions and classes with their own flow into the
> out-of-order block just makes it really hard to figure out what's
> happening where and when.

I obviously agree with all this.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list