views:

172

answers:

4

Recently, when I tried to explain why Rails is a DSL to an intern at my organisation, I was not able to articulate my reasonings 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?

+3  A: 

Ruby is a language that you can use to create a DSL. Ruby on Rails may be considered a DSL (Domain Specific Language) for creating web applications.

Adam Crossland
+6  A: 

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.

Kathy Van Stone
I think the key is that Rails is a framework that combines several DSLs for describing properties of your webapp.
Toby Hede
+1  A: 

Ruby is certainly not a DSL. It's a general purpose language, which is the opposite of a DSL. It is, however, a language that is very suitable as a host for internal-style DSLs. That is; You can use Ruby to create DSLs with.

troelskn
A: 

I don't quite understand the question. Ruby is not a Domain Specific Language, it is a General Purpose Language. It doesn't make sense to call it a DSL, because it isn't one. Therefore the whole premise of the question doesn't make sense.

Jörg W Mittag