Recently, when I tried to explain why Ruby on Rails is a domain-specific language (DSL) to an intern at my organisation, I was not able to articulate my reasoning to the effect I would like to. Maybe I do not understand the space well enough to teach the nuances. Redirecting him to Martin Fowler' article or the Google ranked one InfoQ or other material has not helped much either.
Can some explain why Rails is a DSL with an example / parallel situation which is not voodoo stuff for someone who is fairly new to the world of code? Understanding the ideology might also help in elaborating the intricacies of the rails ecosystem?
Technically, ruby is not a DSL, it just lends itself to writing internal DSLs very cleanly. This link to Martin's Fowler's blog wiki should help clarify things.
Rails has been described as a DSL although I think of it more precisely as a framework that makes very good use of a few DSLs.
Edit: The intro to the public version of Martin Fowler's DSL book has a motivating example, although it is still aimed a bit more at programmers.
Edit again: The "voodoo" example can be useful if you point out that ruby allows ruby code to look like
port 2001
respond :resource=>"/hello" do |request, response|
response.body = "<message>hello</message>"
end
which is cleaner than calling the methods directly. Implementing a DSL can require "voodoo" like code (it is much harder creating a DSL than using one), and in general someone relatively new to coding should worry first about what the DSL does and not so much how it is implemented.
What makes ruby good at internal DSLs includes (1) use of blocks (any language with clean closures has this advantage), (2) method class that do not require parentheses, and (3) the ability to modify classes on the fly (which is what validates
does). There are probably more I haven't thought of.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With