Freitag, 28. März 2008

Builder and DSLs

Naive Question:

If builders allow to define DSLs, and DSL are languages, what is best practise for defining the grammar of this languages?
Or even more naively: when to use verbs, when to use nouns?

E.g.:
goToComputer(){
startUp() {
login(username:'user', passwort:'password')
}
startProgram(name:'thunderbird') {
readMails()
}
}

vs.

computer(action: 'goto'){
computer(action: 'startup') {
loginscreen(action: 'enter username', username: 'user')
loginscreen(action: 'enter password', username: 'password')
loginscreen(action: 'enter')
}
computer(action: 'startProgram') {
}
}
and so on. Of course, it is obvious that the later one is more verbose and needs a convention for the attributes (like "action attribute describes function to execute").

Maybe the best compromise is to use a way to differentiate between verbs and nouns, e.g. write nouns in uppercase.

A related question:

How should the syntax of a DSL be described?

For XML we have schemas, is there need for something like that for DSL? And if yes, how to describe it? BNF seems to be a choice, but when exactly is it needed? Is it overkill? Does it scale?

The reason for such unreflected questions: on the one hand the description of SwingBuilder, on the other hand the longish BNF description of JCR node types. With both I get the feeling that not much more is possible...

Keine Kommentare: