Prototype and Scriptaculous in Action

Posted on Mar 20, 2008 in Blog, Books | 0 comments

Whenever I start a new application, the thought of writing the javascript from scratch – or even just relying on my own libraries I’ve built up during my time as a UI developer – seems cruel and unusual. These days there’s just no reason to not use one of the many available JS frameworks out there: Prototype, jQuery, Mootools, Ext JS, Dojo, YUI – to name just a few of the larger players. These libraries abstract away the never-ending cross-browser idiosyncrasies, provide you with some really extensive practical function libraries, and let you focus on actually implementing your ideas. What a novel idea. Thanks to these beauties, writing javascript is no longer the horror show that it used to be.

For some long-forgotten reason, when I first started exploring these frameworks I settled on Prototype and Scriptaculous. It was probably the beautiful Scriptaculous effects that sold me. Now, having used Prototype on a number of projects I thought it was about time I learned more about how it worked and what other gems lay within its core. The online Prototype API is an excellent resource – and very clearly written – but lacking any sort of search mechanism. For that reason, certain information can’t be found unless you know where to look for it. [Why is there no Array.contains() function? There’s no mention of it in the Array section… Months later I stumble upon Enumerable – ahhhh…!]. The scriptaculous documentation, on the other hand, is god-awful. Navigating their site to find out the simplest thing can take hours of painful searching, clicking, cries for help, blaspheming – finally ending with you either giving up or relying on Google to save the day. Avoid their documentation at all costs.

So anyway, I picked up this book to fill the gaps of my knowledge, especially with regard to Scriptaculous. The reviews I came across were pretty positive, so I thought I’d give it a go.

The book was… well, a little disappointing, to my mind. It’s not a definitive resource, which the author makes perfectly clear. But certain basic things like available selectors for the $$ utility function are omitted with the disclaimer that “we don’t have space to provide a full tutorial on the types of selectors here…”. That bugged me: that’s why I GOT the book, so that All Things Prototype and Scriptaculous would be covered and explained. The $$ function is such a commonly used function, you’d expect it would be covered in depth… wouldn’t you?

But it’s not all bad. I very much enjoyed the chapter on functions, notably the discussion of bind() and bindAsEventListener(). It’s very clearly explained, and I think that closures and binding have finally found a permanent home in my slow-witted brain. The chapter on Prototype Objects wasn’t bad, too: it certainly helped with building my Smart Lists Prototype extension.

Perhaps my excitement over this framework has waned because I’ve been recently exploring another: jQuery. I turned to jQuery out of necessity, since I needed a JS framework that was compatible with Adobe AIR. In a recent post in the “Prototype: Core” Google group, Thomas Fuchs (the lead developer for Prototype) said there were no plans to support Adobe AIR since it “broke the specs”. True enough, but to my mind that’s not enough reason to not accommodate them (if we did this, no script would ever support IE). Other than forbidding eval(), I’m not sure how AIR deviates from the ECMA specification. I’d be curious to know.

Having played with jQuery for a week or so, I must admit I’ve definitely had more “wow!” moments than I did with Prototype. Prototype feels like it’s really geared towards developers, whereas jQuery feels like any bozo (even my retarded cat, “Fish”) could use it. That’s a good sign. I’m going to convert my Smart Lists app to jQuery just out of curiosity to compare the frameworks. Maybe I’ll post about the differences then.

Anyway, to get back on topic and conclude: despite the misgivings mentioned above, “Prototype and Scripaculous in Action” is a good book and well worth the read. Just don’t expect a definitive guide.

Read More

Enterprise Ajax

Posted on Nov 20, 2007 in Blog, Books | 0 comments

I recently picked up a book written by the guys from Nitobi, a Vancouver-based software company, author of the Complete UI package. When I’ve been able to prise the book from my cat’s jaws (who seems to have taken a real fancy to it), it’s a damn good read!

I first heard of Nitobi from a presentation given by the co-founder and President, Andre Charland, at the Adobe AIR Tour in Vancouver earlier this year. Ever since then I’ve had my eyes on the company – they’re remarkably up my alley: emphasis on user experience? Check. Cool company culture? Check. Bloody neat JS-based software? Check. Plus, they’re located in my old backyard (downtown Vancouver).

I’ve been programming in javascript for many years, and endeavored to create dynamic, responsive interfaces that, well, do what you EXPECT them to (see my Generate Data script for one rather nifty illustration). But even my older apps use Ajax in one form or other. Even Form Tools uses the dated, and rather klutzy hidden iframe technique to let the JS interact with the server. But klutzy or not, it solved a problem at the time which couldn’t be solved properly with a costly page reload.

The book itself is well worth picking up. It covers a great deal of ground from the requisite overview of Ajax and OO fundamentals, to the MVC pattern, security issues, pragmatic solutions to common problems like bookmarking and “fixing” the browser back button, and a whole lot more. Two very enthusiastic thumbs up! Fine family fun!

Read More