Background
As defined by Fowler, an internal DSL uses a host language (e.g. Ruby, Groovy) and an external DSL uses a full-blown parser (e.g. ANTLR).
In the latest JNB article, Mark points out that internal DSLs must live within the syntax rules of the host language. This is fine if the audience is composed of software developers, but what if the domain is microbiology?
The following might not be clear:
if( specimen.isBlood && test.isAmpicillin ) {
test.doAlert
}
However, this is debatable: maybe it's ok. Maybe an internal DSL can whittle down its host syntax so that it is reasonable. Debate among yourselves.
The Universal IssueThere is one universal issue for both developers and microbiologists alike:
we make typos. We can bend internal DSLs to look good, but what happens when we make a typo? Will the error message be meaningful for a microbiologist? Or would it reveal the host language with a dev-oriented message?
For example:
if( specimen.isBlood && test.isAmpicillin
test.doAlert
}
Now, what if one were to use ANTLR? Can we get a level of error reporting such as:
Could not understand the statement.
Possible cause is mismatched parentheses.
Please type '-help' for a language synopsis.
Please type '-samples' for quick examples.
What if the grammar were even simpler, such the following, but there is a semantic problem:
if specimen.isAmpicillin and test.isBlood
test.doAlert
Could we get a domain-specific error message such as:
Error: 'ampicillin' is not a specimen
Error: 'blood' is not a test
Check appropriate values for 'specimen' and 'test'
with '-values'.
I don't know the answer for either internal or external DSLs. For the latter, I'm going to this month's
StL JUG to ask the question. See you there.