Archive for June, 2005

Aspects in Javascript?

Thursday, June 30th, 2005

I just read about an interesting library for using CSS selectors to apply Javascript behaviours, courtesy of a link from Ajaxian. The idea is simple: use CSS selectors in Javascript code to specify DOM nodes that Javascript event handlers should be bound to. This abstracts the event handling code away from the HTML. This gives cleaner code, though I’m not sure how useful it will be in practice, for two reasons:

  • It will be slower than just writing the event handlers directly in the HTML. How much slower I haven’t measured, so this may not be a problem.
  • I don’t write much Javascript directly (except when trying out new ideas). Instead I tend to generate it (along with HTML) from other sources, so achieving a separation between Javascript and HTML isn’t an issue for me.

However I don’t want to give a negative view of this library. I think it is really neat, and it has interesting similarities to Aspect-oriented programming (AOP). In AOP you change code by specifying places to add extra functionality. This library is changing HTML by specifying places to add extra functionality. If you squint the right way HTML and Javascript merge into one, so there seems to be a relationship here. I don’t know enough about AOP to know if this analogy opens up any interesting new directions, but I know people who do, and I hope they’re going to comment on this. :-)

A bit more art: Fluxus

Thursday, June 30th, 2005

untypers keep their eyes on a number of weblogs; one of them is Lemondoor, a LISP-related weblog maintained by jjwiseman. In this post, he points us at Fluxus, a very cool looking real-time coding and live-performance engine for sound and visual effects.

http://www.pawfal.org/Software/fluxus/

We don’t like to blow our own horn too hard, but around untyped we do pretty well with a number of languages, and Scheme is a favorite; we have a number of open-source projects written in Scheme, and it drives some of our own research projects as well. Fluxus looks like the kind of platform that we might be able to do some very fun and exciting things with.

Achieving Closure

Wednesday, June 29th, 2005

Todd Ditchendorf advocates the benefits of anonymous classes:

While the XMLHttpRequest class is certainly a major step forward for JavaScript in the browser, you have to admit… this API is crap … Instead of passing a function reference to [the XMLHttpRequest object], why not pass a reference to a JavaScript object? … Notice how [anonymous classes] allow you to package instance properties (fields, variables, attributes, whatever) and instance methods along with the actual callback method … Sure … you don’t need this kind of functionality … you can always just define a bunch of global functions and global variables to be used by your callback function, but, then you lose all the benefits that OO offers with regard to combining state and behavior into a single, encapsulated entity!

While I agree with his statements — the XMLHttpRequest API is crap — the alternative to anonymous classes is not a mess of global variables and functions, thanks to a feature in Javascript known as closures. It seems many Javascript developers don’t know about closures, as they come from the functional, not object-oriented, line of languages, so I thought I’d highlight them here.

Javascript allows functions to return functions, and I think most Javascript developers will be familiar with that. However, some may not know that such a function can reference variables defined in it’s parent function, even after the parent has returned. This means you can write things like:

function makeSayHello(name) {
var sayHello = function() {
alert("Hello " + name);
}

return sayHello;
}

var noel = makeSayHello("Noel");
var matt = makeSayHello("Matt");

noel();  /* Says "Hello Noel" */
matt();  /* Says "Hello Matt" */

Notice that noel and matt refer to the arguments to makeSayHello even after makeSayHello has finished executing. This is very useful when writing callbacks, as it allows you to setup the callback with the parameters it needs avoiding a mess of globals. For example:

function makeCallback(arg1 arg2) {
return function() {
doSomething(arg1);
doSomething(arg2);
}
}

You’ll see this pattern used a lot in our demos. It’s a neat trick and deserves to be better known.

The Canvas: Why It’s Important

Friday, June 17th, 2005

In Safari 1.3 Apple introduced a new canvas tag along with Javascript extensions that enable 2D vector graphics to be drawn directly onto a web page. This extension has since been incorporated in a WhatWG specification and Mozilla have followed up with an implementation that’s available in the latest Firefox 1.1 preview release. We have two demos up here and here. This essentially enables a lot of the power of Flash from within a normal web page.

Apple’s motivation to was to enable Dashboard, but as we discussed earlier the potential for this technology extends much further. Existing web technologies such as CSS, the DOM, and Javascript allow highly interactive applications, as GMail and Google Maps have shown. However there are still some limitations: the developer cannot create custom widgets or draw complex graphics in the web-browser. The canvas solves this problem. Now that Firefox is implementing the canvas it makes it viable to release cross-platform graphic rich applications. This is a whole class of applications that so far the web hasn’t been able to touch. Think about Adobe Illustrator running within your web browser. This is one to watch!

Those Who Wonder Wrap-Up

Friday, June 17th, 2005

On Monday Christian and I went to Those Who Wonder, the degree show for the Graphic and Media Design (Illustration) students from the London College of Communication. In a word: Wow!

(more…)

A bit of art…

Friday, June 10th, 2005

untyped recently had the opportunity to work with Nils Porrmann on a piece that is part of the upcoming Those Who Wonder exhibition showing this weekend.

(more…)

New Design

Thursday, June 9th, 2005

As you may notice, we have a new design that fits in much better with the design of the rest of the site. Enjoy!

Google Summer of Code

Wednesday, June 1st, 2005

Google Summer of Code will pay you $4500 if you complete an open-source project over summer. Only two questions:

  1. When will PLT Scheme join the list of participating organisations?
  2. Where do I sign up?

Seriously, Untyped and other ventures are keeping me busy enough that participating isn’t really viable. However this does look like an excellent opportunity for both OSS projects, and developers with free time.