Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

The Wikipedia article for domain-specific languages seems only to refer to actual languages.

However, I've heard the term "DSL" used to refer to unique-looking coding paradigms encouraged by libraries in "standard" languages.

From Ruby on Rails, for example (from here):

create_table :posts do |t|
  t.string :name
  t.string :title
  t.text :content

  t.timestamps
end

That is Ruby code. It's not it's own language, but it's a unique coding style encouraged by a library in order to make coding in a specific domain more readable.

Is there a separate term for this?

share|improve this question
    
What's a "standard" programming language? –  Larry Coleman Apr 19 '11 at 12:08
    
@Larry Coleman, a "standard" or "general purpose" language is one that is designed for many different applications. Examples are C, C++, C#, Java, Erlang, Ruby, Python, Perl, Lisp, Smalltalk, and others like them. This is in contrast to domain specific languages that are designed for one purpose. Examples of that type of language are: SQL, XML, HTML, CSS, YAML, and others like those. The last category of languages are "regular" languages such as Regular Expressions, CSV files, etc. –  Berin Loritsch Apr 19 '11 at 12:15
    
@Berin: That is the generally accepted definition, but I'm not sure if that's what the OP meant. Substituting "general purpose language" for "standard language" in the second paragraph of the question doesn't seem to work. –  Larry Coleman Apr 19 '11 at 12:18
    
The OP was citing the embedded DSL for database migrations that was implemented in the standard language Ruby. The DSL is 100% Ruby code, just formatted to be a bit more declarative than usual. It's the same approach used by the Ruby build tool Rake. In this case Ruby is the standard language, and the migrations code is the DSL. Similar parallels work with attribute languages and C#, such as NUnit code. Also, the Hamcrest Assertion library is an example of an embedded DSL written in 100% pure Java. Unless I'm reading something wrong. –  Berin Loritsch Apr 19 '11 at 12:22
    
@Berin: I was just nitpicking about the quotes around the word "standard." I'll stop now. –  Larry Coleman Apr 19 '11 at 12:43
show 2 more comments

5 Answers

up vote 12 down vote accepted

I've heard such a thing referred to as an "internal DSL" or an "embedded DSL".

share|improve this answer
1  
Agreed and Folwer has a nice article martinfowler.com/bliki/DomainSpecificLanguage.html and book bookdepository.com/book/9780321712943/Domain-Specific-Languages naming it the same. –  KeesDijk Apr 19 '11 at 7:27
add comment

Just because Wikipedia doesn't mention it doesn't mean it doesn't exist :) I generally use the term DSL for embedded languages within a particular language (and for me, this includes printf and regexes). I like the term "little language" for constrained languages that don't have the full power of a programming language behind it, but may still require tokenization and parsing. But domain-specific language is the right term of art, regardless of whether your language is built using the features of your language or if you're building a completely new language.

I'd use the term DSL in the broader sense as well, for full-on programming languages targeting problems in a particular domain, but I've mostly built DSLs with the help of existing languages, namely Boo and Ruby. If your language supports metaprogramming, or functional abstractions, it's usually possible without much effort to build a DSL in or around the language. (In Boo, I usually build a DSL as an extension to the language using features of the compiler pipeline and the semantic macro syntax).

If you have less control over the syntax tree or the method call syntax is less flexible, you can use method chaining to create a fluent interface, which is a subset of what we think of as a DSL.

DSLs are well supported in Lisp-inspired languages, where you're essentially building a DSL anytime you write code.

As an aside, Donald Knuth also used the term literate programming for a style of programming that's self-documenting because the code serves as a readable document.

share|improve this answer
    
Does this answer the question? –  reinierpost Apr 19 '11 at 9:25
    
My answer is that DSL is the correct term in general, and there's not a special term for one that you build using the features of an existing language. –  JasonTrue Apr 19 '11 at 14:37
add comment

They call those "fluent APIs" or a fluent interface.

Most of the examples are focused on "method chaining", but anything that makes the code look more domain-specific is a fluent api.

http://martinfowler.com/bliki/FluentInterface.html

share|improve this answer
add comment

In 1977, Nick Lawrence coined the term "category language" for this kind of thing. He presented a paper at a 1977 simulation conference, entitled "Simulation Category Languages". These were DSLs embedded in a general-purpose simulation language, to make certain kinds of simulations a lot easier to set up.

At the time, Nick was TI's resident discrete-event simulation guru. He was at UT Austin for a little while, teaching a seminar on discrete-event simulation.

share|improve this answer
add comment

Apart from the internal or embedded DSL name mentioned, these types of things are also sometimes related to the concept of Convention over Configuration where defining some things in a specific manner (or leaving them out entirely) is interpreted in some pre-defined manner (such as the Ruby on Rails example you give, where defining these fields signals something about how they should end up in other layers of the final running system).

share|improve this answer
1  
As powerful as convention over configuration is, that doesn't address the OP's question. The syntax used in the OP's example creates a structure that is interpreted and translated into the vendor specific SQL needed to create or drop the tables. This is how many DSLs work. The fact that the framework knows how to make the conversion or find the migrations to apply is not relevant to the question. –  Berin Loritsch Apr 19 '11 at 11:39
    
@Berin After reading the question again, I'm actually not sure what exactly the OP wants to know. He asks about DSLs, but the example shows both domain-specific notation and convention over configuration at work. His final comment doesn't clarify this either. I mentioned convention over configuration to make sure he doesn't come away from this discussion thinking they are the same thing (or for that matter, even related). But perhaps I am confusing him even more! –  Deckard Apr 19 '11 at 11:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.