This weekend I looked into the Spring MVC framework, and got a bit disappointed with the vast amount of XML configuration that was needed to create a simple starter application.
Then I stumbled upon Apache Camel earlier today, and got a bit happier from the possibility of easy configuration in the Java world.
First, the XML config;
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<loadBalance>
<roundRobin/> <!-- This only support for Camel 1.5 -->
<to uri="mock:x"/>
<to uri="mock:y"/>
<to uri="mock:z"/>
</loadBalance>
</route>
</camelContext>
This is of course horrible; I suppose that the amount of XML for a moderately-sized application would, if printed, fill a binder. (And why is the <roundrobin/> placed where it is? Should't it be an attribute of the loadBalance element?)
Then the Java fluent builder;
from("direct:start").loadBalance().
roundRobin().to("mock:x", "mock:y", "mock:z");
This is much better. It's quite readable, at least if you can read Java. However, the structure of the configuration, that we can understand quite easily in the XML case, is lost.
This issue is fixed in the Scala DSL;
"direct:a" ==> {
loadbalance roundrobin {
to ("mock:a")
to ("mock:b")
to ("mock:c")
}
}
We get a structured and free-form configuration at the same time. It's readable for me, who have quite limited Scala knowledge. My only issue right now is the curlys. I like the way the DSL uses pattern matching in Scala ("direct:a" ==> {...}) fits into this.
If I'd do it in Ruby, I could imagine it something like this:
configure "direct:a" do |route|
route style :roundrobin
route to "mock:a" "mock:b" "mock:c"
end
Readable, structured and sweet.