PyCon DC 2004
Python's creator said, "What will the future bring for Python? Darned if I know. Maybe somebody in the future can bring back the keys to my time machine." In the meantime Guido declared Python 2.2 an ex-release, said 2.3.3 is current and 2.4 will be "better, faster, and bigger". It will be faster thanks to new library modules and more C code. The latest summary of completed and planned changes is in PEP 320: Python 2.4 Release Schedule, and a gentler introduction is in "What's New in Python 2.4" (URLs below). The full details of completed changes are in the file Misc/NEWS in the Python source, and Misc/HISTORY details all the past changes since Python 0.9.0.
Guido said the current dilemmas for 2.4 are deciding on a function decorator syntax, getting people used to generator expressions and speeding up function calls by shrinking the stack frames.
A decorator is a function that takes another function as an argument and returns a modified version of that function. Python's classmethod and staticmethod builtins are decorators. Python needs a generic syntax to apply decorators in the def line, remembering that a function can have multiple decorators. Five syntaxes are under consideration:
def foo [classmethod] (cls, arg1, arg2): # Guido's favorite, and preferred by PyCon hand vote. # Disadvantage: args separated from function name. [classmethod] def foo(cls, arg1, arg2) # Disadvantage: 'def' not at left column. def [classmethod] foo(cls, arg1, arg2): # Disadvantage: function name not near left column. def foo(cls, arg1, arg2) [classmethod]: # Disadvantage: decorator hidden behind long argument list. def foo(cls, arg1, arg2): [classmethod] # Disadvantage: decorator not on 'def' line.
Generator expressions are like list interpolations, but they create an iterator rather than a list. That's good because usually you're going to iterate over it once anyway, so a list would waste memory. The syntax is quite unobtrusive; simply put the keywords in a normal parenthesized expression:
sum(x * 2 for x in range(10))
If there's a comma on either side, an extra pair of parentheses is required. This eliminates ambiguity in argument lists.
The long-awaited Python 3.0 has been put off again, this time until his son Orlijn goes to college (he's now 1 1/2) or until Guido retires or goes on a sabbatical. His top wishlist items for 3.0 are:
convert functions returning lists into generators wherever feasible. ("Iterators are the force of the future.") Users will have to type list(range(10)) if they really need a list.
make the module hierarchy in the standard library deeper.
learn from IronPython, Starkiller and PyPy.
IronPython is a rewrite of Python in C# for Microsoft's Common Language Runtime. Every port of Python to a different virtual machine tests the robustness of the language and standard libraries and often reveals some efficiency tricks that can be ported back to CPython. Starkiller is discussed below; it's a statically typed C++ compiler for Python programs. PyPy is a rewrite of Python in Python. (Yes, some people actually do this.) Q&A on a variety of topics is in the SubEthaEdit notes.
Homage should be paid to last year's most controversial topic, if-then-else expressions (PEP 308). Guido did not see it as important because the if statement exists, but he was willing to add it if the community overwhelmingly favored it and agreed on a syntax. The community could do neither, so Guido rejected it forevermore.
Bruce Eckel gave a humorous talk about static vs. dynamic typing. You can read more about it in the SubEthaEdit notes and in Bruce's Web log (see Resources). He quoted Andrew Dalke's comment about typing: "If you only care if it quacks, you don't need to check that it's a duck." Bruce maintains that even with static typing you still have to do checks at runtime for things the compiler can't catch, so why obscure the code with types and casts? He thinks one's time would be better spent writing a robust automated test suite (unittest) than on debugging type casts.
To me, the three most interesting talks were those discussing Nevow, Quixote and Atop. Nevow is the successor to Twisted Woven, a high-level Web application framework. Because I've worked with Webware and Cheetah extensively, I was curious about the differences. Nevow, like most other non-PSP/PHP servers, is based on servlets. Something parses the URL and invokes a servlet instance somewhere, and a servlet method returns or writes the HTML output. In Webware, that something that parses the URL is Webware itself. In Nevow, as in twisted.web that I described last year, your application class registers itself as the manager of a certain URL part (=directory), and then your
.locateChild(self, request, parts)
method has to handle or delegate everything to the right of that part.
Nevow's most intriguing aspect is its built-in model-view-controller (MVC) framework, which strictly separates generic logic calculations (the data) from the specific view desired (the rendering). A servlet (a Page subclass) associates itself with an HTML template. The template might contain placeholder tags like this:
<span nevow:data="currentMonth" nevow:render="month"> <h1><nevow:slot name="label">Bogus label</nevow:slot></h1> ... </span>
(Here and throughout I've used modified examples from the presentations.) Nevow sees "currentMonth" and calls a method .data_currentMonth in your servlet. That method returns some values needed in the <span>, possibly based on GET parameters or other criteria. Nevow then sees "month" and calls .render_month(self, context, data). That method receives the data returned by the previous method and fills the slot with its actual value:
This replaces the entire slot tag. Cheetah fans note that the template is not pulling values from a dictionary; rather, the method is pushing values into the template. The rendering method also can extract another type of tag, the pattern, which it can use in a for loop to generate repetitive sections, for example, table rows.
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems
Join editor Bill Childers and Bit9's Paul Riegle on April 27 at 12pm Central to learn how to keep your Linux systems secure.
Free to Linux Journal readers.Register Now!
|diff -u: What's New in Kernel Development||Aug 20, 2014|
|Security Hardening with Ansible||Aug 18, 2014|
|Monitoring Android Traffic with Wireshark||Aug 14, 2014|
|IndieBox: for Gamers Who Miss Boxes!||Aug 13, 2014|
|Non-Linux FOSS: a Virtualized Cisco Infrastructure?||Aug 11, 2014|
|Linux Security Threats on the Rise||Aug 08, 2014|
- diff -u: What's New in Kernel Development
- Security Hardening with Ansible
- NSA: Linux Journal is an "extremist forum" and its readers get flagged for extra surveillance
- Monitoring Android Traffic with Wireshark
- Tech Tip: Really Simple HTTP Server with Python
- Readers' Choice Awards 2013
- RSS Feeds
- [<Megashare>] Watch Mrs Brown's Boys Movie Online Full Movie HD 2014
- Cooking with Linux - Serious Cool, Sysadmin Style!
- Linux Security Threats on the Rise