tags:

views:

171

answers:

3

Hi,

I don't know anything in Ruby, but i'm pretty interested in DSLs. And DSL seems to be a buzz word for you community.

Do you actually implement DSLs in Ruby for your own purposes ? If so, how complex and how dedicated are they ?

i've seen this question here, but i'm more interested in your everyday experience.

thanks.

A: 

Its Ruby's speciality, to get everything working very quickly, But it could become tough to manage. I would say, for small or medium DSL projects ruby is awesome. As i haven't created any big DSL project in Ruby, i cannot recommend it(for bigger projects).

Webbisshh
Rails is a DSL and is an enormous project. Works fine. :)
banister
Ya i know, but he was asking about our experience, that's why i said I cannot recommend this.
Webbisshh
My question is to know if ruby developer are actually using this feature. Is this becoming a reflex to implement DSL to solve problems ?
LB
@LB, yes ruby developers often use it.
banister
@banister, what are they doing is my question ? :-). It makes no sense to ask this question in general, but i'm interested in what each one of them is doing (i'm not sure that my sentence is syntactically correct, hope you get the idea though :-) ).
LB
@LB: well, i already showed you what I am doing (see my answer). Everyone, esp. library writers, do what they can to make their APIs easy to use and understand. Look at Sinatra, Rake, etc. If you cruise around github searching for ruby projects you'll find more specific examples of how programmers are leveraging the syntactic flexibility of Ruby to create nice APIs or DSLs. In particular check out the many testing frameworks.
banister
+1  A: 

My own experience writing DSLs in Ruby is quite limited but i've done the following:

(1) An L-System DSL:

Dragon = TexPlay::LSystem.new {
    rule "F" => "F"
    rule "X" => "X+YF+"
    rule "Y" => "-FX-Y"
    angle 90

    atom "FX"
}

(2) An image manipulation tool:

image.paint {
    circle 20, 20, 15, :color => :red
    rect 10, 20, 100, 100, :color => :green
    pixel 40, 40, :color => :white
}
banister
+1  A: 

Here's another example of a Ruby DSL, it's called Mail, and it's a DSL for sending emails:

mail = Mail.new do
    to '[email protected]'
    from 'Mikel Lindsaar <[email protected]>'
    subject 'First multipart email sent with Mail'
end

see here: http://github.com/mikel/mail

banister