classical geek

March 28, 2007

Metaprogramming Javascript

Filed under: Tech, Ajax, Java, Scripting — dave @ 4:41 pm

Within a couple of weeks of almost getting my head around Ruby meta-classes, here’s a link to an interesting presentation on metaprogramming Javascript (in PDF format) by Adam McCrea. I’m not completely convinced that

show("brutus").when("us-state").is("Ohio,Michigan")

really qualifies as a DSL - reminiscent of Prototype’s somewhat cheesy Try.these() - but it’s a pretty mean feat of coding nonetheless.

March 27, 2007

How Sgt. Pepper got his Legs

Filed under: Tech, Ajax — dave @ 10:37 pm
before after

I’m hanging out at the JavaRanch saloon this week answering questions about the new book, and very excited I am to see it in print at last. One reader has asked me this morning why the book changed it’s name from ‘P & S Quickly’ to ‘P & S in Action’ at the last minute, and the Sgt. Pepper lookalike on the cover (see right) acquired a pair of legs in the process. So, let me tell you the story behind that.

I’d started using the Prototype & Scriptaculous libraries in my production code, and realised that they were changing the way that I wrote Javascript. Not just that I was using a new API, but that the authors of these libraries had really figured out how Javascript worked as a language, and had created a set of tools that allowed very fluid and expressive code. As with “Ajax in Action”, my primary motivation for writing was to chronicle my own journey as a coder, and I thought this would be a good subject for a book. Manning’s ‘Quickly’ series are intended to be short and focused, and that was what I had originally planned to write.

As the journey progressed, I realised that there was a lot of context around these libraries. To grok Prototype, you need to grok Javascript’s closures, object literals and other language features, so I ended up writing a comprehensive overview of Javascript the language (something I’d always meant to do, but not necessarily on this project).
Scriptaculous is all about useability and ease of use, so I felt the book needed something about that too. And when exploring Ajax (little Ajax, the request-response bit, as oposed to big Ajax, the whole shooting match), I wanted to measure the impacts of different solutions on network traffic, and render them as charts, so I show you how to do that too.

All of these serve to explain P & S more fully - I’m not interested in writing a dry API guide, I want to explain why the libraries exist, and how you can use them in the real world. But, having done all of this, with a great deal of help from Bear, and latterly Tom, the book was no longer ‘Quick’. And so, Prototype & Scriptaculous in Action was born.

QCon 2: Ruby Meta-programming

Filed under: Tech, Scripting — dave @ 11:37 am

I spent most of the day at the Ajax track, but snuck off upstairs to join the Ruby crowd for Dave Thomas’ talk on Ruby meta-programming. Partly, it was the draw of a big name, but mostly just for the fun of guddling in low-level language stuff. I’d been playing around with closures in JavaScript in my own talk a couple of hours earlier, and wanted to see how somebody else approached that sort of thing.

Dave spent most of the talk whipping up real-time demos in an interactive shell, which beats my Powerpoint hands down. After flashing up a simple ActiveRecord class at the outset, there wasn’t much reference to Rails until the very end, when the Fred and Dave examples came full circle to demonstrate how has_many is added to ActiveRecord classes.

One of the unifying principles in Ruby is that everything is an object, even class definitions. Ruby supports metaclasses (kind of invisible little classes that allow custom members to be added to individual instances of objects. Because classes are objects, a class can be customised via its metaclass too, resulting in something that looks like a static method (to drop back into Java-speak).

Most online resources point to Why’s intriguing Seeing Metaclasses Clearly, or you can visit the dungeons of Dwemthy’s Array if you’re feeling foolhardy and brave (but don’t say I didn’t warn you!). A more sober explanation of metaclasses can be found at mobcode.

Web 3.0 Timeline

Filed under: Stuff, Tech — dave @ 11:36 am

Nat Torkington of O’Reilly Radar (who first appeared on my radar as author ofvthe Perl Cookbook), has written a very nice future timeline of the Web. Nuff said on my part, go have a look.

« Previous PageNext Page »

Powered by WordPress, Supported by SaveOnRefinance.com