Language Design Insight from Python
The Python Enhancement Proposals seem, at first glance, a suprisingly place to find insight into programming language design. On further reflection, though, it appears inevitable that documents designed to justify, explain, and specify new features in a superbly-thought-out language would be models of clarity, conciseness, and interest. Along, with Paul Graham's essays (e.g. on Arc and Lisp), I recommend them to anyone interested in programming or software design (even if you abhor semantically-significant white-space in source code).
PEP 343: Anonymous Block Redux and Generator Enhancements proposes new syntax and keywords for Python. While fairly technical, this gets at the heart of language design: what abstractions and structures get encoded into the syntax, and how? Guido van Rossum, creator of Python, offers specific reasons for preferring one notation over another and insights into the way in which such designs evolve.
Here's an excerpt to give you an idea of the style (don't worry, it makes sense in context):
The idea was to define the template like this:
@with_template def opening(filename): f = open(filename) try: yield f finally: f.close()and used it like this:
with f = opening(filename): ...read data from f...The problem is that in PEP 310, the result of calling EXPR is assigned directly to VAR, and then VAR's __exit__() method is called upon exit from BLOCK1. But here, VAR clearly needs to receive the opened file, and that would mean that __exit__() would have to be a method on the file.
PEP 318 discusses various proposed syntaxes for function decorators, which ended up looking like this:
@classmethod @synchronized(lock) def foo(cls): pass
This was only agreed on, however, after months of battle and hundreds of alternatives, and the PEP has links to all the gory details. It's good to see people passionate about the fine details of programming, even if it means spending weeks arguing over the relative merits of ! and @.
Other interesting PEPs include Iterators (#234), Simple Generators (#255) and Generator Expressions (#289).