Thursday, June 19, 2008

Martin Fowler’s Syntactic Noise in JavaScript

I am closely following Martin Fowler's work on his DSL book. It is very interesting stuff and I wish I had more time to follow it more closely ... His latest post is related to the book and is about Syntactic Noise. This is my humble contribution with attempt to translate his example to JavaScript (btw, you have to read the article to make anything out of this):

var stateMachine = 
new StateMachine(
events: {
doorClosed : "D1CL",
drawOpened : "D2OP",
lightOn : "L1ON"

commands: {
unlockDoor : "D1UL",
lockPanel : "PNLK"

states: {

idle : {
actions : ["unlockDoor", "lockPanel"],
transitions: {
doorClosed : "active"

active: {
transitions: {
drawOpened : "waitingForLight",
lightOn: "waitingForDraw"

I know there is lots of red and I don't use => as is used in most of the examples, but I think I got it pretty good, and actually JavaScript is not that bad at all when it comes to internal DSLs. What do you think?
Oh, and I was just thinking, I bet I can do DSL in MPS that will have 0 (zero) syntactic noise! Keep tuned, I really might. That brings up another question: the example and the whole article is based on text based DSLs (blast, he was talking about internal DSLs, and I thought to be a smart a**) and what about graphical DSLs or Language Workbenches? As I said in some more advanced language oriented tools (MPS) we might use no syntactic nose without sacrificing any clarity. Text presented for clarification in this tools is part of the editor and is not there because of the syntax, you type in only significant data.

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from JQuery Training in Chennai . or learn thru JQuery Training . or learn thru ES6 Online Training. Nowadays JavaScript has tons of job opportunities on various vertical industry.