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.
I think what you probably meant to describe was something
akin to top-down programming
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