6/30/2006
Simple Design: "DSL" Reloaded
I have been silent about DSL for a while. Now, I am back:)
After being thinking for several months, I realized most of time, people don't need domain specific language, they just need the code read more nicely. Then, I come up a idea such kind of requirement doesn't need to involve heavy implementation such as grammar, parser or compiler, it could be simple, and it should be simple!
So, is Ruby or Smalltalk the right selection? I have to say, I don't think so. The reason why I am not very keen about the idea using Ruby as the environment to embed so called "DSL"( I still refer to the nicely looking code as DSL, sorry about that), is because the language is not invented to support hosting DSL. Method missing or closure or initial block are not intended to use this way:
publishing agreement dated '9/20/2005' with_author 'Joe W. Author', social('555-493-3920') for_title 'DSLs for Dummies' report do calculate 'Royalties', as net_retail_sales.during(last_six_months) * 20.percent endWe are using Ruby too tricky!!! We are not using it, we are hacking it. The side effect is understanding the inner mechanism behind nice code becoming harder and harder, which is leading us to a dangerous direction. That reminds me of similar experience of C++. After introducing template into C++, I think except STL and several other excellent framework addressing some critical issue (mostly performance), others are simply too smart to be useful. Tons of frameworks inside Boost are just trying to make the code looking nicer... My point is if the language did not support the way of writting code we want, don't hack it using powerful trick to hack it even if the father of the language encourage you to do so. (I don't know the attitude of Matsumoto, but I do know Bjarne speaks a lot about extending C++ using framework). If not hacking a flexible scripting language, what can we choose to implement the so called DSL? The one thing I am sure if we need to write complex grammar for a new DSL (actually a English-like language), we are going the wrong direction. Because human language is too complex to be handled by formal grammar specification. So, I like the philosophy behind embeded DSL(Ruby again...or Smalltalk). The DSL is still embeded in a GPL, but the GPL should support hosting DSL so the implementation doesn't need to be tricky. The initial idea came into my mind back to this Feb. But at that time, I thought what we need is a new lightweighted GPL, but it still need to be weak typed, mordern featured scripting language just like Python, Ruby. Part of the reason is I had another nice idea about how to implement a weak typed scripting language effciently in JVM, but I didn't have passion to carry it into reality. This lead me to a not-that-simple-design... Sadly or luckily... I have to say, after several months, I realized it should be more simple than a new scripting language. Then, what is the simplest desing? How about this: assertThat(characterSet, contains('a')); compared with assert_$1$_contains_$2$(characterSet, 'a'); then fommatted to: assert characterSet contains a what we need is a Eclipse plugin to write and read java file in a different view. further more we can that Eclipse displaying inner class like a closure. and $this$ could aslo be a part of the method name to support: list.add(item); list.add_$1$_to_$this$(item); add item to list
Comments:
<< Home
Clipper's preprocessor had such feature 15 years ago :-)
Look at #command/#translate directive:
http://www.itlnet.net/Programming/Program/Reference/c53g01c/ng12000b.html
Few examples can be found here:
http://www.itlnet.net/Programming/Program/Reference/c53g01c/ng122d3c.html
Look at #command/#translate directive:
http://www.itlnet.net/Programming/Program/Reference/c53g01c/ng12000b.html
Few examples can be found here:
http://www.itlnet.net/Programming/Program/Reference/c53g01c/ng122d3c.html
The problem is if you use a preprocessor to translate source code from
list.add_$1$_to_$this$(item);
to
add item to list
then it is not valid source code anymore. My point is, we don't need actually translate, or meta programming any kind of source code, we just need to think the source code as model, and we see it in different view. One view is normal source code, one view might be human language like instruction list. So, that is why, I think what we need is a Eclipse plugin, not hacking a existing scripting language, not a new scripting language, even not a meta programming system(preprocessor).
list.add_$1$_to_$this$(item);
to
add item to list
then it is not valid source code anymore. My point is, we don't need actually translate, or meta programming any kind of source code, we just need to think the source code as model, and we see it in different view. One view is normal source code, one view might be human language like instruction list. So, that is why, I think what we need is a Eclipse plugin, not hacking a existing scripting language, not a new scripting language, even not a meta programming system(preprocessor).
Not to sound pedantic, but Python is strongly typed, not weakly typed.
Some references:
http://www.artima.com/weblogs/viewpost.jsp?thread=7590
http://diveintopython.org/getting_to_know_python/declaring_functions.html
http://www.ferg.org/projects/python_java_side-by-side.html#typing
Okay, this is pedantic. Sorry. :-)
I agree with your other points about being too tricky with Ruby. In the Python world, we went through this "too tricky" phase with Zope and its clever way of mapping URLs to objects via a thing called "Aquisition". Aquisition is an interesting theory, but only from experience did people realize that it's too tricky, too magical, leading to more bugs, and was too hard to debug. I'm very interested to see if in a few years Rails is considered "too tricky" for its own good. I reserve the right to be wrong about it, though. :-)
Some references:
http://www.artima.com/weblogs/viewpost.jsp?thread=7590
http://diveintopython.org/getting_to_know_python/declaring_functions.html
http://www.ferg.org/projects/python_java_side-by-side.html#typing
Okay, this is pedantic. Sorry. :-)
I agree with your other points about being too tricky with Ruby. In the Python world, we went through this "too tricky" phase with Zope and its clever way of mapping URLs to objects via a thing called "Aquisition". Aquisition is an interesting theory, but only from experience did people realize that it's too tricky, too magical, leading to more bugs, and was too hard to debug. I'm very interested to see if in a few years Rails is considered "too tricky" for its own good. I reserve the right to be wrong about it, though. :-)
Yes, python is strongly typed...
I thought using Ruby to make code not looking like ruby code is too tricky. But Ruby on Rails is not. It is a excellent example of how ruby could be a developer DSL. Using RoR, the code could be very clear about developer's intention, while the code is still using plain ruby code. What I am against is trying to use Ruby to write business DSL, making the code very human language like.
Post a Comment
I thought using Ruby to make code not looking like ruby code is too tricky. But Ruby on Rails is not. It is a excellent example of how ruby could be a developer DSL. Using RoR, the code could be very clear about developer's intention, while the code is still using plain ruby code. What I am against is trying to use Ruby to write business DSL, making the code very human language like.
Subscribe to Post Comments [Atom]
<< Home
Subscribe to Posts [Atom]