Wednesday, March 28th, 2007
Metaprogramming / DSL JavaScript Presentation
I wish I could have seen Adam McCrea give a presentation on JavaScript Metaprogramming and how:
-
-
with(JavaScript) {
-
metaprogramming.is("possible");
-
}
-
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:
-
-
create_dynamic_field("show", "us-state-field", "country", "United States");
-
create_dynamic_field("show", "province-field", "country", "Canada");
-
create_dynamic_field("show", "brutus", "state", ["Ohio", "Michigan"]);
-
morphs into the following DSL:
-
-
show("us-state-field").when("country").is("United States");
-
show("province-field").when("country").is("Canada");
-
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.












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!
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?”)
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
Great presentation!
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.
powerful concept. great code.
Not a fan of the last example. How about:
trade(”state”).to(”Canada”).when(”us-state”).is(”Ohio”);
Steve O -
Nicely done!
I love it! Esp. with Rails. Opens up all kinds of possibilities.. :)
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?
Great ideas! I love making JS more natural and this concept really refactors the implementation details away. Good call on the circular reference, BTW.
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.
wow powerleveling lord of the rings power leveling maple story power leveling
wow power leveling
I love it! Esp. with Rails. Opens up all kinds of possibilities.. :)
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
Hi that’s a wonder ful story about DSL I really appreciate it. Excellent Dion, Keep up good work.
Leoni Online Art Gallery
That is really a tremendous resource for Computer scince student. Thanks for share it.
Denver Tax Attorney