Asymmetrical View

OSCon Day 1


Andrew and I arrived for OScon 2008 registration and took advantage of the continental breakfast before heading up to the Intro to Python.

O’Reilly had the registration process pretty streamlined. They had a long bank of laptops which you needed only enter your registration code, or your email address (if you registered on the OSCon conference web site). Register, then walk up to the materials station and pick up your ID and badge card.

There were plenty of juices, coffee, fruit and pastries. There was also plenty of seating. To either O’Reilly’s or the Oregon Conference Center’s credit, things were very well organized.

Python in 3 Hours

The first conference room we were in must have had seating for a few hundred people and it was effectively full. There was limited space for each attendee and their items (it was at least cramped for me) – though they anticipated a laptop per person – so there were plenty of power strips laid along every other row of tables within easy reach of every single seat. It was well planned and laid out.

The intro to Python got underway at 8:30 and although it was geared toward an audience with some programming experience, it assumed (as the title suggested) no python experience. Steve Holden was a great speaker, filling in twice with anecdotes while technical issues were worked out with equipment (once was a mis-configuration of his laptop, the other was a power interruption).

Python is a very capable language. It is more consistent about its OO and syntax when compared to Perl. The python community is also a lot bigger on the use of common conventions. This is mostly focused on formatting (one expression per line), in-line documentation and coding style in general.

Functions are first class types, you can assign a function to a variable, you can implement the equivalent of funcall and apply in python. Functions can be passed as arguments. Python supports positional parameters, default values for function params and calling functions, any function, with positional arguments, named arguments, a tuple of arguments (similar to funcall), or a dictionary (an indirect way of using named arguments).

Python actually has a lot of features which were inspired by functional programming (including one of my favorites: list comprehensions).

Python is byte-compiled, like Java. You write code in a .py file, and the first time it is loaded as a module (import), python compiles the code for you. The time stamp check of the .pyc vs the .py file is transparently handled by python – no explicit make or compile step.

Strings are immutable, which is something that helps Jython be a natural fit in the JVM.

Python supports list destructuring, based on tuples. It’s easier to show an example than to try to explain:

  a, (b, c) = (1, (2, 3))

  print a,b,c => 1, 2, 3

Tuples, and this kind of binding syntax, are widely used in processing things like lists, and maps.

An interesting feature of the language is the pair of functions, local() and gobal(). local() returns a dictionary (Python’s name for a Map), of all of the variable bindings (and values) that are visible in the current scope (exclusive of global variables). globals() returns the variables in the entire module’s scope (not local, lexical or class scope, and not global in the sense of a Perl global – not universally global).

Other Highlights

The yield() form, is like a weak kind of continuation.

for, and while loops can have an else clause which is executed when the form does not execute.

The Python try/catch form (try/except/finally) can have an else form, again, which is executed if no exception was thrown in the try block.

Introduction to Django

After a break for lunch, both Andrew and I attended the Introduction to Django, presented by Jacob Kaplan-Moss.

Django is an MVC framework for Python for rapid development of interactive web sites. It is an MVC framework very much in the spirit of Ruby on Rails – I’ve done some work in Rails and the parallels are very close between the two frameworks.

Django has a code generation framework, an ORM layer (which is very similar to Rails’ ActiveRecord), an html template system (with a default syntax based on PHPs smarty template system), and integrated support for testing.

Django has an interesting testing feature called doctests. If you’ve worked with an interactive language with a REPL, you have probably used it to explore the behavior of code and to informally test the code. Doctests are a way of (almost literally) taking a cut and paste of the interactive session and vivifying the transcript as a regression test. I like the idea of a recorded test, but as Andrew and I talked about it he convinced me that the literal representation wasn’t the best choice for implementing those kinds of tests. I do like the reduction of effort that comes with that kind of testing and recognize the inherent informality of it.

All that said, Django (like Rails) is big on doing test driven development.

I looked up the status of Django on Jython and apparently it’s close to being a 1.0 release (nothing I’d recommend for use at my employer at the moment, but Sun has hired people to work on Jython and Django is one of the frameworks they are concerned with supporting).

I’m looking forward to tomorrow.