The Artima Developer Community
Sponsored Link

.NET Community News Forum
Anders Norås on DSL Development in C#

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
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Anders Norås on DSL Development in C# Posted: Jul 13, 2007 3:01 PM
Reply to this message Reply
Summary
In a pair of recent blog posts, Anders Norås explains how to define a domain-specific language in C#.
Advertisement

Domain-specific languages, or DSLs, received a fair amount of attention lately. A mini-language tailored to a specific task or problem domain can increase developer productivity, and result in higher quality code. In a pair of blog posts, I'm coming down with a serious case of the DSLs! and Behind the scenes of the planning DSL, Anders Norås explains how to define a simple domain-specific language in C#:

Writing DSLs is a little different from the regular object oriented programming style. You might have noticed that the [example] class has a verb for its name rather than the usual noun. This allows us to have a natural starting point for writing out the "sentence" explaining our intention...

Rather than returning an instance of the type we want to create, the operations on the [example] class return descriptors which we will use to collect the information needed to create these types. These descriptor types is the backbone of the DSL. The DSL is basically a fluent interface. With some exceptions, every method or property in the fluent interface returns an instance of the class it is defined on allowing operations to be chained together.

It is more difficult to write a fluent interface than a plain old API, and I agree with Martin [Fowler] that it takes quite a lot of thought to get the grammar right. I've found that it is best to start with a test case and just write the "sentences" before starting to implement the actual language. Not only does this help you to come up with a good language, it also helps create all of the classes, methods and properties that are needed...

What do you think are the most important principles in coming up with a good DSL?

Topic: Partial Methods for Partial Developers Previous Topic   Next Topic Topic: JetBrains' ReSharper 3.0 Delivers C# Productivity Aids, VB.NET Support

Sponsored Links



Google
  Web Artima.com   

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