The Artima Developer Community
Sponsored Link

Agile Buzz Forum
InternalDslStyle

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Martin Fowler

Posts: 1573
Nickname: mfowler
Registered: Nov, 2002

Martin Fowler is an author and loud mouth on software development
InternalDslStyle Posted: Oct 24, 2006 2:22 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Martin Fowler.
Original Post: InternalDslStyle
Feed Title: Martin Fowler's Bliki
Feed URL: http://martinfowler.com/feed.atom
Feed Description: A cross between a blog and wiki of my partly-formed ideas on software development
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Martin Fowler
Latest Posts From Martin Fowler's Bliki

Advertisement
InternalDslStyle dsl 24 October 2006

An internal DSL (often called an Embedded DSL) is a DomainSpecificLanguage that is written inside an existing host language. It's a common way of thinking in a number of programming language communities - particularly the Lisp community. It's now gaining a lot of attention as DSLs are a common way of thinking in the rapidly growing Ruby community.

When people talk about internal DSLs I see two styles: internal minilanguages and language enhancements.

An internal minilanguage is really using an internal DSL to do the same thing as you would with an external DSL. You consciously decide to use a subset of the full GPL for a minilanguage section of your program. It might look something like this (example from my Language Workbench paper)

mapping('SVCL', ServiceCall) do
  extract 4..18, 'customer_name'
  extract 19..23, 'customer_ID'
  extract 24..27, 'call_type_code'
  extract 28..35, 'date_of_call_string'
end
mapping('USGE', Usage) do
  extract 9..22, 'customer_name'
  extract 4..8, 'customer_ID'
  extract 30..30, 'cycle'
  extract 31..36, 'read_date'
end

This is all valid ruby, but it's use of a subset of ruby makes it seem almost like a custom DSL.

Unlike an external DSL you are limited by the syntax and programming model of your host language, but you don't need to bother with building a parser. You're also able to use the host language features in complicated cases should you need to.

The alternative way of using internal DSLs is quite different to anything you might do with an external DSL. This is where you are using DSL techniques to enhance the host language. A good example of this is many of the facilities of Ruby on Rails. Look at these bits of Rails validation

validates_numericality_of :age
validates_uniqueness_of :ssn
validates_format_of :length, :with => /^\d+(in|cm)/

Reading these bits of Rails's validation, it looks like we've given the ruby language new keywords. Of course we haven't modified ruby, this is all clever metaprogramming. But it feels like we've enhanced the ruby language.

These are both very useful techniques. As with any classification there's a fuzzy line between them (Rake could be thought of either way.)


Read: InternalDslStyle

Topic: The fear that drives the RIAA Previous Topic   Next Topic Topic: Mount Blue

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use