A Domain Specific Language to Describe a Web Application Model

The web applications I typically write often have a lot of similarities in them. They usually have a similar architecture, follow the same conventions, use the same libraries, etc. Perhaps another way of putting it would be to say that they follow a similar set of patterns. I have a particular way of programming and my web apps reflect this.

This however has made me wonder: just how much of an application could be abstracted out and defined within a domain specific language? I have no doubt that much of my apps could be done this way. But how do I go about this? In my reading and tinkering I’ve created small frameworks (or would interpreter be a better word?) that take a DSLs and help to build part of an app for me. What I’m thinking though is on a bit bigger scale: like generating my entire model from a DSL and eventually some views and other portions of my application. But starting from scratch to create a language and framework to build most of my app for me is probably a bit overkill. So, I will just start with my model.

My model, as is probably the case with others, is fairly formulaic. Of course there is some customization involved but getting the initial SQL, service objects, business objects, etc. created is fairly trivial – just monotonous and time consuming. Which is one reason why you find people using tools like Transfer ORM and Hibernate. Sure, it wouldn’t be that difficult to actually write all the classes that and write all the SQL an ORM creates for you but it definitely would consume a lot of time – time that could be better spent making the application better or getting it done faster (or both). Doing all that manual work also creates a bigger chance that errors will be introduced since you’d be writing so much more code by hand.

This is why I’ve started getting excited about the possibility of domain specific languages generating my applications or portions of them. The idea of creating a simplified language to allow me to rapidly define my app (or part of it) and cutting out much of the repetitive aspects of development is an exciting idea.

The type of DSL I’m talking about is called a horizontal DSL if I understand correctly. Horizontal DSLs deal with the technical aspects of app. There are also vertical DSLs that align more with business processes and ideas rather than the technical side of things.

To start off I’ve worked up a DSL that I hope to start using for the model in my apps. There is still a lot of work to do like creating the framework to transform the DSL into actual code but first I must come up with a usable DSL to define my model in. So far, this is what I have come up with (it is a bit simplified for this blog).

Note: Much of this DSL I did not originate on my own but from other sources such as Peter Bell’s blog and presentations. His articles and presentations have given me a lot of inspiration in this and much of his examples I have used in this DSL.

                <include name="PersonDAO" />
                <include name="OtherDAO" />
                <include name="AnotherDAO" />



            <pluraltitle>Human Beings</pluraltitle>

                <property title="Identification Number" name="personID" datatype="number" columnname="person_id"></property>
                <property title="Name" name="personName" datatype="string" columnname="person_name">
                    <validationrule name="required" value="true" />
                    <validationrule name="maxLength" value="50" />

Right now I’d say I’m fairly happy with this DSL. That said, I have very little experience in working with them so only time will tell. I’d love to hear what people’s thoughts on it are though.