May 16th, 2008

Hacking away at GWT5

There’s a lot of progress going on integrating Script.aculo.us and YUI-EXT (which are both effects and widget libraries for web pages, targetted at writing vanilla javascript) into GWT - the combination java to javascript compiler and widget/effects library by Google.

One of the strengths of GWT is that, due to java’s explicit static typing (I’ve talking about this before) GWT can determine, with very fine granularity, which code is actually used, and which code isn’t.

This is nice in reference to effects/widget libraries, because not sending to the browser the code for the effects/widgets that you don’t use is a nice boon; you can in effect use such a library even for just one small effect without worrying about forcing another 50k to download for every client. The digg homepage could use some of this treatment, which clocks in at a 3MB download for the whole thing.

So, while wrapping around YUI-EXT or scriptaculous is certainly a fine effort, the real solution is to rewrite it all in GWT code.

Here’s some effects I quickly hacked together: Source + demo: tipit-gwtlib.

Queues and stack traces12

A lot of java apps (in particular Lombok, the single thread webserver I’ve been working on, but there are lots of apps where this can help) employ queues and separate threads to handle the stuff inside them.

One of the problems with this is utterly pointless stack traces. The stack trace is simply of the logistics around the daemon thread handling the queue, and not the code event where the faulty job got introduced to the queue.

A simple way to help yourself is to store a stack trace at the time the job is introduced to the queue. e.g:

public void addToQueue(Job job) {
    Throwable stackOnQueue = new Throwable();
    synchronized ( this ) {
        job.setStackOnQueue(stackOnQueue);
        jobQueue.add(job);
        notifyAll();
    }
}

public void run() {
    while ( running && !Thread.interrupted() ) {
        synchronized ( this ) {
           Job nextJob = jobQueue.poll();
           if ( nextJob != null ) try {
               handleJob(job);
           } catch ( Exception e ) {
               //e's stack trace here isn't of much use...
               //but job.getStackOnQueue() is much more useful!
           } else wait();
    }
}

Ah, yes. TCO and Programming.0

This guy gets it - a generic rant against the notion that less characters must be better programming.

It’s got enough humour to keep you reading, too.

Finally!0

A way to sanely do IO and imperative work in Haskell, and a way to sanely do complex modelling in java, in one convenient marriage.

Where are we going again?2

A long time ago, Object Oriented was seen as the fix for what all that was wrong in Functional programming land (after all, OO hasn’t been around nearly as long as the functional paradigm). Yet now a lot of articles insinuate that Functional is a step up.

What’s going on here?

some historic perspective courtesy of Axel.

Excellent reality check article2

A nice, balanced look at the pros of typing. It foregoes the usual duds like ‘you have fewer type mismatch errors’, but digs into the real benefits.

sound in webbrowsers withOUT flash30

A while ago I developed a canvas-based version of bomberman. It’s a fairly dynamic game, in a browser, no flash.

Unfortunately it uses canvas which doesn’t work on IE6 (or IE7) though it works on the other 3 target browsers (Opera, firefox, and safari). Fortunately, again, google created a toolkit that fakes canvas support using an IE only thing. I haven’t looked at it yet, but it should definitely work.

Aside from that little roadblock, the other big thing that flash can do and vanilla JS+HTML (or so people think) can’t, is sound. Specifically, both sound effects, and background music.

A toolkit called SoundManager 2 is doing the rounds on delicious and company; it allows you to run and control sounds from javascript, but it works by interfacing with flash, which plays the music.

Well, I checked, and you can run sound using just JS+HTML - dynamically!

I’d like your help though: Please check what happends on your own browser. The issues to look at is, obviously: does it work at all, but also: Does sound begin playing immediatly after hitting the button for it? Obviously, to serve as a sound effect in response to hitting a button or some game event, it needs to play immediately.

All the stuff in action (view source to see how to do it, there aren’t many tricks) right here!

GWT headsup - plans for 2007 Q12

This post on the GWT newsgroup lists All plans for 2007 Q1.

Check out #1: making java1.5 language features (foreach, generics, autoboxing and unboxing, etcetera) work in GWT! w00t!

Seriously cool java: F30

Chris Oliver and company at Sun are doing some extremely neat work with ‘F3′ - a descriptive add-on to java (it compiles to .class files) that completely revolutionizes the way you build GUIs. Without sacrificing type safety it makes writing GUIs a total snap, and, most importantly, the F3 code is extremely simple to maintain - a common problem with GUI code, as it tends to be difficult to see the structure when you’re down in the trenches wrestling the code.

His latest Cool F3 Demo on his blog is a fun showcase to check. He’s managed to hack video in there (unfortunately, for now, by way of QT4J, so you need both java AND QuickTime. Mac users can rest easy, it’ll work out of the box on any moderately recent mac) and some graphical effects.

With this, you can no longer say that java GUIs tend to look ugly. At least, this way, there’s nothing stopping you from making them work right and look good.

I’m neck-deep in web building at the moment, but if there’s a graphics-heavy desktop app you need to build, I suggest you have a good look.

GWT - download it now.6

… because it’s that good (here). I’ve built a rather extensive webapp (on contract) inside of 2 months with it, and it’s one giant AJAX fest. In the mean time my server-side stuff consists entirely of static plain files (the stuff GWT compiles to) and some simple servlets that read and write JSON.

Which means my code is extremely maintainable and simple, and I get a free API out of the deal for others to use.

It’s building full webapps with just Java (servlets), Java (GWT), Java (Jetty) and CSS. No HTML required. No fancy java framework required - because writing servlets that read and write JSON code is trivial, and Jetty can do COMET if you need it. No need to know much about browser quirks. No need to know anything about HTML.

It doesn’t get any easier than that to get into web development.

There’s an interesting talk on compiling Java to JavaScript by Scott Blum, Google’s lead at the GWT project, about how Java makes GWT the best javascript toolkit on the block. I suggest you read it - it’s filled with tiny little goodies that are much easier with a statically typed language.

Full Disclosure: pyjamas is the python version of GWT. It starts with a nicely arrogant introduction and it’s not actually finished or practical yet. I doubt it’ll ever be as efficient as GWT is in producing tight, fast, small, javascript.

Imhotep theme designed by Chris Lin. Proudly powered by Wordpress.
XHTML | CSS | RSS | Comments RSS