3 ms·
Haml is an external DSL. Sinatra is an internal DSL. Rubyists insist on using the term so much because Ruby's linguistic flexibility makes it easy to define t
by AndrewO 17y ago
Haml is an external DSL. Sinatra is an internal DSL. Rubyists insist on using the term so much because Ruby's linguistic flexibility makes it easy to define them, so they're constantly doing it.
Martin Fowler is often credited with coming up with the distinction between the two. The concept is similar to a "fluent interface" from a different point of view.
http://martinfowler.com/articles/languageWorkbench.html#InternalDsl http://martinfowler.com/articles/languageWorkbench.html#Inte...
http://martinfowler.com/dslwip/InternalOverview.html http://martinfowler.com/dslwip/InternalOverview.html
- wheels 17y agoOk, so the answer is, "because Rubyists have redefined that phrase"? ;-) The sweetening of the syntax in Sinatra seems to be rather straightforward. I assume it's something like: # internal route stuff @routes = {} def get(method, &block) @routes[method] = block end # user provided code get 'foo' do puts 'foo' end # something hooked up to execute at the end of the file while input = gets.chomp @routes[input].call if @routes.include? input end I find it really hard to call that a language – it's just a clever use of normal Ruby syntax.
- AndrewO 17y agoOk, so the answer is, "because Rubyists have redefined that phrase"? ;-) Well, by name dropping I was hoping to avoid the appearance of that. :-) Fowler certainly writes about Ruby a lot, but I'd hope he's perceived as general enough to not just be a "Rubyist" (I don't know what he primarily uses). But he also points out that Lisp is a perfectly good host environment for internal DSLs (he calls it the "doyen of internal DSL thinking"). And I also brought up the "fluent interface" thing to suggest that you could call it that if it made you happier. For my tastes, I'm fine with the idea that a "language" reuses a more general purpose language's interpreter and libraries. YMMV. I assume it's something like:... http://github.com/bmizerany/sinatra/blob/work/lib/sinatra/base.rb#L836 http://github.com/bmizerany/sinatra/blob/work/lib/sinatra/ba... Sure looks similar, but as you can see from all the code above the method there's a lot more going on. But hey, at least they didn't need to write a parser. ;-)