

DSLs in CoffeeScript - 6ren
http://amix.dk/blog/post/19614?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+amixdk+%28amix.dk+blog%29&utm_content=Google+Reader

======
jashkenas
I'm not too sure where most of these examples fall on the line between DSLs
and just regular CoffeeScript functions (I think the latter), but to pitch in
with another, here's Arel DB querying:

    
    
        Post.where published: yes
    
        Account.joins('customer').where customer: name: 'Pepsi'
    

Which compiles into this JavaScript:

    
    
        Post.where({
          published: true
        });
        Account.joins('customer').where({
          customer: {
            name: 'Pepsi'
          }
        });

~~~
rst
Well, you could also say the Ruby examples are just invoking regular Ruby
functions. Either way, you've got what Martin Fowler[1] calls an "internal
DSL" (as opposed to an "external DSL", which has a parser and syntax of its
own).

[1] <http://martinfowler.com/bliki/DomainSpecificLanguage.html>

------
Almaviva
I think it's really easy to confuse "cute" with "more productive", and the
vast majority of attempts at creating DSLs are the former. I think very few
are worth their weight, since it seems I always eventually have to be aware of
their exact nuances and code paths anyway, and that being so I'd much rather
just see ordinary syntax.

~~~
DanielRibeiro
Coffeescript optional parenthesis and much shorter syntax for closures are a
big help in diminishing the noise, which is crucial to make a DSL. Without
these, some DSLs become so cumbersome that they are in fact unwieldy.

For instance: nobody uses nested closure[1] techniques in java, because
anonymous classes are too much of a verbose implementation of closures, not to
mention that they can only close over final variables, making it even more
cumbersome

[1] [http://my.safaribooksonline.com/book/software-engineering-
an...](http://my.safaribooksonline.com/book/software-engineering-and-
development/ide/9780132107549/internal-dsl-topics/nestedclosure_)

------
gulbrandr
Please do not post links with utm junk in the URL.

