Thursday, September 13, 2007

Nevow Athena: AJAX/COMET with Twisted

Some of you may remember when, given 5 seconds to say something about Nevow's AJAX capabilities at the PyCon Web Framework panel, I said "we were there first." I was serious about that. If you take the time to dig through the dusty attics of Twisted's and Divmod's svn repositories, you'll see it too.

Not that I blame anyone for not knowing, though. If there are any two crimes that Twisted devs are guilty of (among potentially uncountably many) they would be:
  1. being frighteningly clever, and
  2. not sharing the useful bits of the cleverness with the world at large.
We're trying hard to really start sharing the goodness, though, honest!

Along these lines, we've got a series of tutorials about Athena that will be published "real soon, now." Initially, we're going to put out some intro text and two basic tutorials. Follow-on tutorials will cover advanced topics and/or basic ones in more detail.

It will be very exciting, though, to bring the power and elegance of Athena to the masses :-)

Personally, I've found that writing Athena apps (with its tightly bound Python and JS) provides ease of use and peace of deterministic structure in an arena (AJAX/COMET application development) that is usually littered with the bodies and casualties of poor planning, poorly established boundaries between application components (in requirements, architecture, and implementation), and poor education.

I look forward to community feedback on the tutorials: it's a complicated topic that will be condensed into only a little code in each fully functional example. The need for clarity and the defeat of confusion is paramount.

Technorati Tags: , , , , , ,

6 comments:

ScW said...

Dude! I was so there and I remember that panel. Your comment was one of several highlights. Good times...

But I am really, really, really looking forward to the Athena stuff. Digging Nevow... not great at it... but like it.. so adding some AJAXy goodness to the mix would be nice.

Duncan McGreggor said...

Awesome, man! I've just committed the "final" (before the peer review) draft of the "echo application" tutorial. It seems pretty human and humane, to me. And I've really enjoyed writing it (with edits by Glyph). Before I go to bed tonight I want to finish the prose for the "chat application" portion of the tutorial, and then I'll put it into review for committing to trunk -- at which point there will be another blog post or two... probably with screenshots ;-)

Stay tuned!

Calvin Spealman said...

I really want to love Athena, I promise! I've used it, I've enjoyed it, but I just can't bring myself to love it. Comet gives me a bad feeling. I suspend my laptop with web apps open. I leave them running for days. I do lots of things that make me think Comet just isn't right for a lot of uses, but Athena doesn't give us a choice.

Besides, my increasing love of REST makes me get a funny feeling when I have to design my server side components so tightly coupled to these JavaScript "classes" and I can't access the server side stuff in a predictable way without that JavaScript. Where is my safe testing at? Oh, yeah, I can test the Python class _without_ the network at all. I can do tests on the JavaScript with nit.

Still, I can't shake this funny feeling.

glyph said...

As to REST: Yes, COMET is a different architectural pattern to REST. It has different features. For example, REST effectively has no facility to dynamically publish updates without polling - once you need that feature, you need to step outside the paradigm somehow. However, with Nevow, you can write an application that uses COMET for user interfaces and also provides a REST interface to the same objects (and heck, a WS* interface too, if you really wanted that for some reason) without much more work; so I make no apologies that Athena doesn't support REST directly.

As to testing: we've actually gone a step further in testing your JavaScript. Nit is hard to build into an automated build process, and it's too easy to write nits that depend on too much browser state. Instead, you can now write regular unit tests for your javascript that don't depend on templates or Python, and drive them with the test support in nevow.testutil.JavaScriptTestCase. The Nevow/Test directory has some examples.

Donovan Preston said...

I think I found the first COMET related checkin to twisted. It has the very inconspicuous checkin message:

Features added: Added the beginnings of two way asynchronous event handling to Woven.

Meaning javascript could trigger Python code on the server at any time, and Python could trigger javascript in the browser at any time. This version used iframes instead of XmlHttpRequest, but the core is there.

5 years ago. Ahh, good times.

http://twistedmatrix.com/trac/changeset/4285

Duncan McGreggor said...

Oh, sweet! I missed that one. It's nice to have a reference to that :-)