The Wayback Machine - https://web.archive.org/all/20061113072435/http://simon.incutio.com:80/

Tamarin

On Tuesday, the Mozilla Foundation and Adobe announced the Tamarin project, an open-source ECMAScript virtual machine based on the ActionScript engine used by Flash Player 9.

Frank Hecker's overview of what this means is useful, but the Tamarin source code itself provides this interesting piece of historical insight:

AVM+ is the ActionScript Virtual Machine

AVM+ offers an order of magnitude performance increase over the "Classic AVM" in Flash Player 7. Our performance target is 10X.

AVM+ implements ActionScript 3.0, the new version of the ActionScript language that is compliant with the ECMAScript Edition 4 standard.

AVM+ is also built for modularity. It will be part of the Flash Player, but is a self-contained module which can be incorporated into other programs with ease. It may also be submitted to the ECMA standards organization as a reference implementation of ECMAScript Edition 4.

Adobe's reputation for solid engineering shines through here - it seems that what is now Tamarin was designed for integration with other applications from the very start.

The most important thing we can expect from this is a serious improvement in JavaScript performance in the Mozilla family of products, thanks to Tamarin's JIT compiler that can convert ECMAScript bytecode to machine code at runtime. JavaScript/Ajax applications will run faster, and the Mozilla applications themselves will perform better as much of their UI is written in JavaScript and XUL.

This performance boost will benefit other applications as well. Tamarin is being integrated with SpiderMonkey, which is used in a variety of applications such as the Yahoo! Widget Engine.

Reading through Brendan Eich's technical overview of Mozilla 2, it looks like the Mozilla team also plan on taking advantage of this performance boost to move code from C++ to JavaScript 2 in many places, simplifying their code base and reducing the likelihood of security flaws in the code.

Even in these buzzword filled days of Ajax and Web 2.0, JavaScript is still seen as a poor cousin to so-called "real" programming languages. With a high performance open-source VM like Tamarin available, maybe more developers will start to re-examine JavaScript's role outside the browser.

Fun with ctypes

This probably only works on Intel-based OS X machines:

>>> import ctypes
>>> print ctypes.c_char_p(
    -16 * 4096 + 0x1600
).value
Your karma check for today:
There once was was a user that whined
his existing OS was so blind,
he'd do better to pirate
an OS that ran great
but found his hardware declined.
Please don't steal Mac OS!
Really, that's way uncool.
   (C) Apple Computer, Inc.U??VWS?5P

Adapted from dsmos.c in Understanding Apple's Binary Protection in Mac OS X by Amit Singh.

Graphing requests with Tamper Data

I spent the weekend in Boston, speaking at GBC/ACM's Deep Ajax seminar with Alex Russell and Adrian Holovaty. I'll be posting some notes on this later, but I wanted to share a really neat Firefox extension that Alex showed me: Tamper Data.

Tamper Data is an extension for intercepting HTTP requests and modifying them. I have very little interest in this functionality myself, but hidden deep within the extension is the ability to do this:

Screenshot of Tamper Data graph of www.yahoo.com

That's a graph showing what happens when you load up www.yahoo.com. It shows every component of the page - JavaScript, CSS, images - and when each component started and finished loading. You can use it to get an idea for how long it took between the HTML starting to load and the browser beginning to pull in the CSS, then the images, and so on. It's a superb visualization of what happens when a page is loaded.

Unfortunately, if you install and run the extension (Tools -> Tamper Data) you'll see this instead:

Screenshot of Tamper Data user interface

To get the graph, you have to right click in the main data grid and select "Graph All" from the context menu. Be sure to hit "clear" before loading a page that you want to graph or you'll end up seeing data from other pages too (you should shut down GMail or similar to prevent their polling requests from polluting the graph).

It's a great tool but it's pretty well hidden. If you're looking for a side project, implementing the same functionality in a smaller extension (maybe as an extra tab in the Page Info screen) would be a significant service to the web development community.

Keep your JSON valid

I'm a big fan of JSON, and it's great to see it turning up as an output option for so many Web APIs. Unfortunately, many of these APIs are getting the details slightly wrong and in doing so are producing invalid JSON.

JSON isn't just the object-literal syntax of JavaScript; it's a very tightly defined subset of that syntax. The site has a spec (illustrated with pretty state machine diagrams) and there's an RFC as well.

By far the most common error I've encountered relates to object keys. In JSON (unlike in JavaScript) these MUST be double-quoted strings. In fact, ALL strings in JSON must be enclosed in double quotes (JavaScript also allows single quotes; JSON does not).

Valid:

{ "name": "Simon" }

Invalid:

{ name: "Simon" }
{ 'name': "Simon" }
{ "name": 'Simon' }

It's worth reviewing the other key differences between JSON and JavaScript. Remember, all valid JSON is valid JavaScript but the opposite is not true; JSON is a subset.

This stuff matters. Python's excellent simplejson module is a strict parser; it refuses to consume invalid JSON. If you're building a JSON API it's worth taking the time to ensure you are valid - I suggest installing Python and simplejson and trying the following:

$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) 
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
>>> import urllib, simplejson
>>> url = "http://your-api.org/your-api/json"
>>> simplejson.load(urllib.urlopen(url))

Try it against a few JSON supporting sites. You might be surprised at the amount of invalid JSON out there.

As with outputting XML, the best way to avoid these problems is to use a pre-existing JSON generation library rather than rolling your own. I've had good experiences with simplejson for Python and php-json for PHP.

What I'm excited about, post-conference edition

Wow, I've had a really busy month. I've attended (and spoken at) BarCamp London, Media in Transition, d.Construct, RailsConf Europe, Euro Foo and EuroOSCON. All were excellent, and each one nicely complemented the others. I'm exhausted. I think my brain is full.

My favourite question to ask new people I meet at conferences is "what are you excited about?". It's better than "what do you do?" (their job might not be as exciting as what they do in their spare time) and often gets a really interesting reply. People often ask me the same back, so here are three things that have been catching my attention recently.

Finally, since I've blogged the last two releases of Python I can't resist saying a few things about the new Python 2.5. It's all good, but the stuff that really stands out is the addition of sqlite3, ElementTree and ctypes to the standard library. Batteries included!

The YDN Python Developer Center

I recently had the opportunity to put together the Python Developer Center for the Yahoo! Developer Network. YDN is one of my favourite parts of Yahoo! so I jumped at the chance, and the resulting mini-site is now online (YDN blog post here).

The bulk of the content is the HOWTOs, which discuss ways of accessing Yahoo! APIs using Python:

I had a lot of fun playing around with different ways of accessing the APIs and working out which ones were the most natural fit. The HOWTOs use urllib, urllib2 and xml.dom.minidom from the standard library, but also discuss httplib2, ElementTree and simplejson as third party libraries that are worth investigating. Naturally, feedparser is the recommended tool for accessing Yahoo!'s multitude of RSS feeds.

Python really is a fantastic language for exploring web service APIs. All of the example code for the HOWTOs was first written in an interactive prompt and then copied to a file once it was working. Test-first development is certainly an important technique, but the power of interactive development should never be underestimated.