DSL - No Fluff Just Stuff

DSL

Posted by: Venkat Subramaniam on November 5, 2005

There are a number of things going on in software development that's exciting me. I couldn?t say
that a year ago, but this time, its different.

This morning, I am getting excited about DSL (probably because I was chatting about that before
I went to bed).

I think Domain Specific Languages are going to play a major role in how we develop in the future.
I plan to spend more time on this topic later. But for now, my excitement is from seeing the
Groovy example I will talk about here.

You sure have written code to generate XML. You know how tedious and boring that is. If you have
used DOM (or one of the other APIs out there) you would agree that task of generating XML must
be given to condemed prisoners.

Now, take a look at this Groovy code:

map = ['C++' : 'Stroustrup', 'Java' : 'Gosling', 'C#' : 'Hejlsberg']

bldr = new groovy.xml.MarkupBuilder()

bldr.languages {
    for(entry in map)
    {
        language {
            name (entry.key)
            author (entry.value)
        }
    }
}

The output from from this program is:

<languages>
<language>
<name>C#</name>
<author>Hejlsberg</author>
</language>
<language>
<name>Java</name>
<author>Gosling</author>
</language>
<language>
<name>C++</name>
<author>Stroustrup</author>
</language>
</languages>

Now, if I change it to:>

map = ['C++' : 'Stroustrup', 'Java' : 'Gosling', 'C#' : 'Hejlsberg']

bldr = new groovy.xml.MarkupBuilder()

bldr.languages {
    for(entry in map)
    {
        lang (name:entry.key) {
            author (entry.value)
        }
    }
}

I get: >

<languages>
<lang name='C#'>
<author>Hejlsberg</author>
</lang>
<lang name='Java'>
<author>Gosling</author>
</lang>
<lang name='C++'>
<author>Stroustrup</author>
</lang>
</languages>


Now, isn?t that cool. Groovy MarkupBuilders show me the light of DSLs.
Imagine writing code that speaks your domain. It is soon becoming a reality.
There are so many exciting tools for this. How adapting to this is your language of use?
Exploring DSL further is one of my tasks for December. I am planning on a new talk related to this.
More about this later.
>

Venkat Subramaniam

About Venkat Subramaniam

Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., creator of agilelearner.com, and an instructional professor at the University of Houston.

He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is a regularly-invited speaker at several international conferences. Venkat helps his clients effectively apply and succeed with sustainable agile practices on their software projects.

Venkat is a (co)author of multiple technical books, including the 2007 Jolt Productivity award winning book Practices of an Agile Developer. You can find a list of his books at agiledeveloper.com. You can reach him by email at venkats@agiledeveloper.com or on twitter at @venkat_s.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »