| OSCon Day 1 |
[Jul. 21st, 2008|10:57 pm] |
Andrew and I arrived for 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 wich 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.
The conference room we were 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 expected a laptop per attendee - 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. It is also a lot bigger on conventions, broadly adopted by the community. This is mostly focused on formatting (one expression per line), in-line documentation and coding stle in general.
Functions are first class types, you can take a function into 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 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 fo the .pyc vs the .py file is transparent, it's automatically handled.
Strings are immutable, which is something that helps Jython be a natural fit in the JVM.
Python supports some destructuring constructs, based in what it calls tuples. It's easier to show an example:
a, (b, c) = (1, (2, 3))
print a,b,c => 1, 2, 3
Tuples, and this kind of binding syntax, is 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, which is like a weak kind of continuation - for, and while loops can have an else clause, which is executed when the form terminates normally (as opposed to breaking out of the loop) - 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
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 a small site in Rails and the parallels were 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 all that great a 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 HMS at the moment, but Sun has hired people to work on Jython and Django is one of the frameworks they are concerned with making work).
I'm looking forward to tomorrow. |
|
|
|
|