[Python-ideas] Statement local functions and classes (aka PEP 3150 is dead, say 'Hi!' to PEP 403)
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat Oct 15 02:02:19 CEST 2011
Eric Snow wrote:
> I'd
> vote for this in-order usage:
>
> given:
> a = 1
> b = 2
> def f(a=given.a, b=given.b):
> ...
You seem to be taking the view that hiding the names in
an inner scope is the most important part of PEP 3150,
but I've never seen it that way.
> I like the in-order variant because it's exactly how you would do it
> now, without the cleanup after:
>
> a = 1
> b = 2
> def f(a=a, b=b):
> ...
> del a, b
But the assumption that "in-order is better" is the very
thing under dispute. The entire reason for the existence
of PEP 3150 and/or 403 is that some people believe it's
not always true.
> Also, the in-order given statement is easy to following when reading
> code, while the post-order one is less so.
I suspect we may be misleading ourselves by looking at
artificially meaningless examples. If meaningful names are
chosen for the intermediate values, I think it can help
readability to put the top level first and relegate the
details to an indented block.
gross_value = net_value + gst_amount given:
gst_amount = net_value * (gst_rate / 100.0)
I can't see how it hurts to put the subsidiary details
after the big picture, any more than it hurts to write your
main() function at the top and other things it calls
after it.
--
Greg
More information about the Python-ideas
mailing list