Diff: [root] @ 1c4688c5151 | faq | css

DSLs suck!

File created: code/dsls-suck [Diff]

-- /dev/null++ b/code/dsls-suck
@@ -1 +1,53 @@
h1. DSLs suck

DSL is for "Domain Specific Language":http://en.wikipedia.org/wiki/Domain-specific_language. But does every domain needs its own language?

Rarely. DSLs are mostly invented because people are too lazy to use available tools and/or plagued with NIH syndrome.

h2. What's so bad about DSLs?

Their poor quality as programming languages. DSLs are mostly created in haphazard fashion. First, some moron decides that instead of using YAML, .ini or even XML (because this will bloat his program so much that his suckless friends will turn away from him), he will just throw together some kind of key-value config parser.

bc. mycoolvalue 2
mycoolstring wtf

Nice and cuddly, as all the small things are. Then he needs value names with spaces and strings with newlines. Welcome to "escaping hell":delimiters_must_die! Then he thinks that he needs to reuse values in other values, so he throws together interpolation, using some silly character like ^. Seriously, who's ever going to use it in string. And if he does, we can escape it...

Then he needs cycles, then variables, then functions, and we have a crappy reimplementation of PHP. That's what called DSL.

h2. Examples

Here's a config for "FDM":http://fdm.sourceforge.net/. I copied it over, changed some vars and not touching it anymore.

bc.. set maximum-size 127M

action "inbox" mbox "%h/mail/inbox"

account "pop3s" pop3s server "pop.gmail.com" port 995
user "voker57@gmail.com" pass "pass"

match all action "inbox"
match "From:.*bob@idiot\\.net" action drop

p. This piece of shit contains examples of most DSL failures. Bizarre interpolation, strings with custom escaping, crappy variables. Pathetic excuse of a language.

The other well-known DSL is SQL. If you think it does not suck, try inserting a binary value in a table. Then write some logic for stored procedures.

h2. Alternatives

EDSLs. This is like DSL, only with real programming language. Here's an example in Ruby, that's from "Merb":http://merbivore.com request router:

bc. match('/wiki/diff/:sha/:pagename', :pagename => /.*/, :sha => /[a-f0-9]+/).to(:controller => :page_diffs, :action => :showpagediff).name(:showpagediff)
match('/wiki/diff/:sha', :sha => /[a-f0-9]+/).to(:controller => :page_diffs, :action => :showdiff).name(:showdiff)
match('/wiki/src/:pagename', :pagename => /.*/).to(:controller => :wiki_pages, :action => :src).name('articles_src')

Clean, human-readable, absolutely standard. Other good (and more embeddable) languages exist, like "Lua":http://www.lua.org/.

In most cases, you don't even need a full-fledged programming language. You can use a declarative one, like "YAML":http://www.yaml.org/, which even has substitution and few other useful tricks. You can use "JSON":http://www.json.org/, "INI":http://en.wikipedia.org/wiki/INI_file, or even "XML":http://en.wikipedia.org/wiki/XML, just for fuck's sake, don't write your own DSL. Please.

h2. Things that do it right way

"XMonad":http://xmonad.org/: it uses Haskell as its config language.
"ion3":http://en.wikipedia.org/wiki/Ion_(window_manager), "awesome":http://awesome.naquadah.org/ use Lua for configs.
"MongoDB":http://www.mongodb.org/ uses "BSON":http://bsonspec.org/ for its API and JavaScript for DB-side logic.

By Voker57 on 2011-03-01 22:29:28 +0000