5 ms·
DSLs are great when they bring the code closer to being a description of the problem / logic / assertions. One example of a highly successful embedded DSL is re
by sorbits 17y ago
DSLs are great when they bring the code closer to being a description of the problem / logic / assertions. One example of a highly successful embedded DSL is regular expressions.
A DSLs made by using a language’s features for operator overloading, magic constants, and similar, has the advantage that the “code” in the DSL is part of the original source, but it also has the big disadvantage that it tends to show many compromises due to limits of the host language, so the syntax will be arcane and non-standard.
Though this isn’t specific to Ruby/Rails. I think the problem is twofold, 1) the advantage of having the DSL embedded and 2) the advantage (for the creator of the DSL) of not having to build an actual compiler for the DSL.
Something like Ragel¹ solves #1 by being a preprocessor.
¹ http://www.complang.org/ragel/ http://www.complang.org/ragel/
- bensummers 17y agoHaving implemented a web app framework using a preprocessor, I found it was a bit of a pain to write and use. So using the language features makes sense to get the job done. But I was trying to question whether or not a DSL was the right way to go for a web app. If you use as many of the standard features and keywords as possible, there's no ambiguity over what a special keyword means.