Why RubyOnDotNet : DSLs are the future (and you need a dynamic language to create a DSL)
Aaron summed up nicely a talk I enjoyed at ReMix. Like David I see a future wherein we are all programming in a plethora of mini-languages aka DSLs. (Have I mentioned that I love Rails and ActiveRecord?).
I was discussing David’s talk with a co-worker who was struggling to grasp why Ruby (or other dynamic languages) are better suited for creating DSLs. At first I was having a tough time making the case for Ruby, until I realized that my co-worker was actually thinking about Fluent Interfaces when talking about DSLs. (David had demo’d putting together a Fluent Interface in C# as part of his talk, in addition to showing off the RSpec, Rails and ActiveRecord DSLs in Ruby).
The breakthrough for him (I think!) was looking at Linq as an example. The extension methods .Where, .GroupBy etc. truly are a great example of a fluent interface and lead to powerful, expressive code. However they are downright klunky and noisy when compared to the new Linq keywords added to C#3.0 like from blah in foo where ... select .... The new Linq keywords truly form the DSL, while the extension methods are just a static-language implementation detail better left to the compiler to generate and abstract the developer from.
Any Ruby or C# programmer can create a fluent interface. But in C# that is as far as you can go. If you want to create a DSL - new keywords, new syntax, new grammar - you need to rely on the compiler writers (or very difficult, kludgy hacks). This is where a dynamic languge like Ruby shines. In Ruby you the developer have the ability to create the DSL. As RSpec, ActiveRecord, etc. show Ruby makes DSLs a breeze.
I find it interesting that Fowler pointed to this ability to create DSLs as the true differentiator between Java/C# and Ruby (as well as Smalltalk, Lisp, etc) back in 2004!
As a result it certainly seems to me that certain languages are more suited to internal DSL than others.
…
I often find it hard to put into words why it is I enjoy programming in Smalltalk or Ruby so much more than in Java or C#. The most talked about reason is static versus dynamic typing, but I’ve always felt that that discussion misses the point. The friendliness towards internal DSLs is much closer to the essence of the difference.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply