Wednesday, March 28th, 2007

Metaprogramming / DSL JavaScript Presentation

Category: Announcements, JavaScript, Presentation

<>p>I wish I could have seen Adam McCrea give a presentation on JavaScript Metaprogramming and how:

javascript
< view plain text >
  1. with(JavaScript) {
  2.   metaprogramming.is("possible");
  3. }

His slides do a good job at explaining the talk (which is tough to do).

The presentation quickly delves into an example where he evolves the solution to the spec:

show us-state field when country select box is “United States”
show province field when country select box is “Canada”
show brutus when us-state select box is “Ohio” or “Michigan”

A typical solution in JavaScript:

javascript
< view plain text >
  1. create_dynamic_field("show", "us-state-field", "country", "United States");
  2. create_dynamic_field("show", "province-field", "country", "Canada");
  3. create_dynamic_field("show", "brutus", "state", ["Ohio", "Michigan"]);

morphs into the following DSL:

javascript
< view plain text >
  1. show("us-state-field").when("country").is("United States");
  2. show("province-field").when("country").is("Canada");
  3. show("brutus").when("us-state").is("Ohio, Michigan");

and it goes on from here to delve deep into the world of dependencies and metaprogramming with JavaScript.

Related Content:

14 Comments »

Comments feed TrackBack URI

I’m really glad you found the slides useful on their own. I was a little worried they would provide little benefit without the accompanying talk, so I’ll be expanding the talk into a multi-part tutorial on my blog very soon (as in, I think I’m posting part 1 this afternoon). Thanks for the link!

Comment by Adam McCrea — March 28, 2007

I feel like an idiot for having to ask this, but what is “DSL”?

Wikipedia’s disambiguation page suggests that maybe it means “Domain-specific programming language, a programming language designed to be useful for a specific set of tasks” or possibly “Data Serialization Language, a way to describe data independent of a programmable language”. I’m guessing it’s the first of those.

I’m also guessing it’s _not_ “Dominican Summer League, a branch of affiliated minor league baseball played in the Dominican Republic” or “Design Science License, a copyleft licence for intellectual property”.

The suggestion I’m getting at here is to please don’t assume your readers are familiar with every CS-ish acronym floating around out there.

(Nice: my captcha challenge question for this comment is “What three letter acronym is what we use to style web pages?”)

Comment by lbjay — March 28, 2007

Beware of is identifier usage — is will be a reserved keyword in near future (http://www.mozilla.org/js/language/es4/core/lexer.html).

VS

Comment by Valery Silaev — March 28, 2007

Great presentation!

Comment by Kevinin — March 28, 2007

lbjay -

DSL in the context of this presentation means domain-specific language. Sorry the presentation isn’t more explicit. I prefer the leave my slides as high-level as possible and let the accompanying talk flesh out the details. Since few were able to actually hear the talk, I’ll be going into more depth in the tutorial.

VS –

Whoa! Good catch… I’ll need to adjust that vocabulary.

Comment by Adam McCrea — March 28, 2007

powerful concept. great code.

Comment by kenji — March 28, 2007

Not a fan of the last example. How about:

trade(“state”).to(“Canada”).when(“us-state”).is(“Ohio”);

Comment by Steve O — March 28, 2007

Steve O -

Nicely done!

Comment by Adam McCrea — March 28, 2007

I love it! Esp. with Rails. Opens up all kinds of possibilities.. :)

Comment by Jason — March 28, 2007

Great code, thanks for publishing the presentation.
It would be cool if there would be a DSL for client side forms which would talke care of presentation, validation and extra features. Is there some of this in the making?

Comment by Jojo — March 28, 2007

Great ideas! I love making JS more natural and this concept really refactors the implementation details away. Good call on the circular reference, BTW.

Comment by Aaron — March 29, 2007

I love it! Esp. with Rails. Opens up all kinds of possibilities.. :)

Comment by hotindir — June 27, 2007

I love it !
Especially with Rails !

did I tell you I got a new girlfriend and I was able to do all sort of new things with her because of Rails ?

signed:

rails fanboi

Comment by railsfanboi — July 28, 2007

Hi that’s a wonder ful story about DSL I really appreciate it. Excellent Dion, Keep up good work.
Leoni Online Art Gallery

Comment by Leoni Bellagio — August 8, 2007

Leave a comment

You must be logged in to post a comment.