Clojure vs. MDSD
04.07.2013
Permalink
How the smart Java developer improves on expressiveness
- Recognize boilerplate
- Decide which meta tool to use
- Start wizard "New Xtext project"
- Write the grammar
- Create language infrastructure
- Write the generator
- Distribute IDE plugins to team
- Extend the CI build process
- Continue to solve real problems
How the Clojure developer improves on expressiveness
- Recognize boilerplate
- Write another 10 lines of Clojure code
- Continue to solve real problems
Ok, that was unfair.
Actually with Xtext or MPS or any other of those meta tools you play
in a different league of language engineering. Your syntax is not
bound to Clojure, you can have very sophisticated editors with code
completion, navigation, cross-language refactoring and so on. You can
target at host platforms and languages that are completely different
from your preferred programming language. You could even go entirely
for cross-platform development.
But that comes at a cost. You should ask yourself: Why do I need it?
And does it outweigh the cost?
I know Java enterprise development quite well. When it comes to
expressiveness, conciseness and simplifying things Java does a bad job
compared to Clojure. The JVM platform is great, the language is
cumbersome. It doesn't allow you to raise your level of abstraction.
This is the most important reason why modeling for this type of Java
software is still an important topic. Entities, Web Services, UI
forms, build and deployment scripts and other artifacts: all suffer
from the syntactical restrictions of XML and Java. And a neat
grammar/metamodel that captures only the essential information,
combined with a code generator, is a huge relief of your eyes and your
brain. Once you have these things in place...
The story is completely different in Clojure. Lisps in general allow
you to raise your level of abstraction
within the language. The
ultimate weapon is the use of macros: Clojure code that creates
Clojure code. The "generator" step is included in the compiler. No
different language, no coupling to IDEs, no complication of your build
process. You may have less convenience using your brand-new language
constructs, but you can reach them only in minutes. And you can share
them like any other piece of code in your team.
This changes fundamentally the way you work on code. More than once I
looked at my Clojure code and thought: "Oops, that API is like a DSL."
I didn't want to go meta. It just happened. Frictionless.
I understood the
LOP paper by Martin Ward
like there are distinct, recognizable steps:
- think about how you want to write down solutions,
- then create the necessary languages,
- then solve problems using them.
In Clojure, there aren't any conscious steps. You simply live in a
world that fosters expressiveness. And in consequence: no Clojurian
would ever think about creating an external DSL. And if you'd tell
them "well, the Xtext parser gives you a model, which is based on an
Ecore metamodel, and then you use Xtend to quickly create a
generator", they would just walk away, shrugging their shoulders.
To conclude: in a Clojure world external DSL tools, or specialized
code generators will not have any future. They seem just like
incidental complexity, required to make working with a broken language
bearable. I know, most of us do not earn their money in the Clojure
world. That makes these external meta tools valuable. But not
desirable.