[Python-ideas] Long Live PEP 3150 (was: Re: Statement local functions and classes (aka PEP 3150 is dead, say 'Hi!' to PEP 403))

Raymond Hettinger raymond.hettinger at gmail.com
Mon Oct 17 09:53:39 CEST 2011


On Oct 16, 2011, at 12:16 AM, Nick Coghlan wrote:

> The current draft of PEP 3150 is available on python.org:
> http://www.python.org/dev/peps/pep-3150/

FWIW, I think the word "declarative" is being misused.
In the context of programming languages, "declarative"
is usually contrasted to "imperative" -- describing
what you want done versus specifying how to do it.
http://en.wikipedia.org/wiki/Declarative_programming
I think what you probably meant to describe was something
akin to top-down programming
http://en.wikipedia.org/wiki/Top%E2%80%93down_and_bottom%E2%80%93up_design#Top.E2.80.93down_approach
using forward declarations:  http://en.wikipedia.org/wiki/Forward_declaration .

Looking at the substance of the proposal, I'm concerned that style gets in the way of fluid code development.

Using the PEPs example as a starting point:
sorted_data = sorted(data, key=sort_key) given:
    def sort_key(item):
        return item.attr1, item.attr2
What if I then wanted to use itertools.groupby with the same key function?
I would first have to undo the given-clause.

AFAICT, anything in the given statement block becomes hard to re-use
or to apply to more than one statement.  My guess is that code written
using "given" would frequently have to be undone to allow code re-use.

Also, it looks like there is a typo in the attrgetter example (the "v." is wrong).
It should read:

   sorted_list = sorted(original, key=attrgetter('attr1', 'attr2')

When used with real field names, that is perfectly readable:

   sorted(employees, key=attrgetter('lastname', 'firstname')

That isn't much harder on the eyes than:

   SELECT * FROM employees ORDER BY lastname, firstname;


Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111017/06fbe094/attachment.html>


More information about the Python-ideas mailing list