Ruby DSL’s vs YAML vs XML

I am using Ruby based DSL’s for a number of tasks in my current project. But one day it struck me - am I using the right tool for the job, could there be a better, more simple solution?

Some DSL’s I use are simply declarative and look something like this:

I find that quite readable, but it requires me to maintain code that handle the DSL. So I figured, what if I used YAML? It is simple, and using it would mean less code to maintain.

After doing some experimenting, this is what I came up with:

In my opinion, the YAML is not as readable as the Ruby DSL. I also find it more error prone as those dashes are sort of tricky.

XML?

With the correct schema, errors can be avoided, but it is just too much text in there, it gets heavy and verbose.

The verdict was to stay with the Ruby DSL’s - their readability and flexibility are well worth the effort of maintaining a separate parser - which is quite short really.

  • del.icio.us
  • Digg
  • description
  • Technorati
  • Reddit

5 Responses to “Ruby DSL’s vs YAML vs XML”

  1. Johan Lind Says:

    What about the other YAML syntax:

    Let’s ask stuff: { What is 1+1?: {2: correct, 3}, Vad is 2+3?: {1, Infinity, Don’t know, 5: correct}}

  2. Marcus Says:

    That\’s JSON you mean, right? I do not think it is just that terse though.

    I believe it would be something like:

    {\”quiz\”: {\”text\”: \”Let\’s ask stuff\”, \”alternatives\”: {[\”text\”; 2, \”correct\”: true …

    It\’s better than XML, but I find it slightly less readable than YAML. Too many strings etc.

    JSON is really useful to send data over the wire, but I still prefer my DSL.

    Thanks for the input though.

  3. Jon Tirsen Says:

    I’ve actually gone full circle and started doing external DSLs again. Check out Racc, the Yacc parser generator for Ruby.

  4. Valeriu Palos Says:

    …or Coco/Rb (better than Racc in my opinion): http://www.zenspider.com/ZSS/Products/CocoR/ (generates pure Ruby) http://raa.ruby-lang.org/cache/coco-rb/ (generates C extension to Ruby) , or even StringScanner: http://www.ruby-doc.org/core/classes/StringScanner.html

  5. Markup languages/bad taste use of O’Reilly books · Twonilblankblank Says:

    [...] A cursory search on YAML vs XML turns up interesting blog entries from Marcus Ahnve and Digital Hobbit. [...]

Leave a Reply