Tag Archives : Domain Specific Languages


Morning Coffee

  • Libor Soucek continues our conversation about durable messaging. We still don’t agree, but he says he “fine” with durable messaging. He does go out of his way to differentiate between *enterprise* and *supporting* systems. But when you’re building connected systems, does that differentiation still matter?
  • After taking a few months off, John deVadoss is back at the blog. Check out his Big SOA/Little SOA post. I especially like his snowball analogy “How do you build a big snowball? You start with a small snowball.”) though he’s also on this “middle out” bandwagon. Do we really believe “middle out” works, or are we just saying it because we know top down and bottom up don’t? And John: You’re welcome!
  • Anyone coming to the Microsoft SOA & Business Process Conference this fall? Maybe we can have a shindig / blogger dinner / unconference / something?
  • Remus Rusanu writes about SSB’s dynamic routing. One of the (many) cool things about SSB is that all the addressing is logical, not physical. Routing is what binds logical addresses to physical addresses, and it’s extensible.
  • Martin Fowler discusses the value of sticking to one language. I agree with his points about large frameworks being as difficult to learn as a new language. I’ve said for a long time “If you build a framework, build tools to make it easy to use your framework”. Language is obviously a core example of a tool. Another interesting point Martin makes is the traditional “intimate relationship” between scripting languages and C, but that the rise of JVM & CLR makes them impossible to ignore. Does the need to play well in a managed environment hinder a C based language like Ruby when compared to a natively managed scripting language like Powershell? Finally, Martin’s “jigger of 80 proof ugliness” quote made me laugh.
  • Politics 2.0 Watch: EJ Dionne says thatDailyKos is doing for Democrats what Rush Limbaugh did for Republicans almost twenty years ago: mobilization. Josh Marshall points out that “what’s happening today is vastly more participatory and distributed…than anything happening back then.”

Service Factory Customization Workshop Day One

No morning coffee posts for the first half of this week, because I’m in training thru Wednesday. Day one was mostly overview of GAT and DSL, which was review for me. Today we’re starting to dig into some of the new stuff they’ve build for the new version of WSSF, so I’m paying much more attention today.

This isn’t your typical workshop in that the content is sort of being generated on the fly. As I type, we’re voting on what we’re going to cover for the next two days. Most classes I’ve been in are pre-programmed, the teacher doesn’t ask the class what topics should be covered and what order. There isn’t even one “teacher” - there are five folks from p&p including the architect, dev lead and PM of WSSF that are tag-teaming. Even the hands-on labs aren’t completely ironed out – they’re evolving the lab directions as we do the labs. It’s atypical, but it works.


Thoughts on C# Fluent Interfaces

Martin Fowler points to a couple of articles by Anders Norås on building internal / embedded domain specific languages in C#. Anders has built a DSL for creating calendar events and tasks, like you might expect to do in Outlook. Here’s an example:

ToDoComponent planningTask = 
   Plan.ToDo("Plan project X"). 
      StartingNow. 
      MustBeCompletedBy("2007.08.17"). 
      ClassifyAs("Public"); 
planningTask.Save(); 

EventComponent planningMeeting = 
   Plan.Event("Project planning meeting"). 
      RelatedTo(planningTask). 
      WithPriority(1). 
      At("Head office"). 
      OrganizedBy("jane@megacorp.com", "Jane Doe"). 
      StartingAt("12:00").Lasting(45).Minutes. 
      Attendants( 
         "peter@megacorp.com", 
         "paul@megacorp.com", 
         "mary@contractor.com").AreRequired. 
      Attendant("john@megacorp.com").IsOptional. 
      Resource("Projector").IsRequired. 
      ClassifyAs("Public"). 
      CategorizeAs("Businees", "Development"). 
      Recurring.Until(2008).EverySingle.Week.On(Day.Thursday). 
      Except.Each.Year.In(Month.July | Month.August); 
planningMeeting.SendInvitations();

It may not be as clean as a say a Ruby version might be, but even with all the parens and periods it’s still pretty readable. Fowler calls this a fluent interface, a term I like better than “internal DSL”.

Two things jumped out at me reading Anders’ entry on how he built this fluent interface. First, there’s a lot of code to make this work. Anders didn’t publish the code, but he did admit:

“Believe me, there will be a lot of code when you’re done. I’m almost there with this DSL, and at the time of writing it consists of 58 classes not including the API and tests.”

That’s 58 classes just to implement the fluent interface, not counting the underlying EventComponent API. That’s a lot of non-business logic code to write. How many projects are willing to invest that kind of time and effort to build a fluent interface? (I would guess “not many”)

However, I bet there’s a lot of template-izable code in Anders fluent interface. When he writes about keeping the language consistent by “creating branches within our grammar using different descriptor objects”, I can help but think about parser development with YACC and the like. These tools typically use a DSL like BNF. Maybe we could build a DSL for building fluent interfaces?

Second, Anders makes a very interesting point about the structure of the fluent interface code:

Writing DSLs is a little different from the regular object oriented programming style. You might have noticed that the Plan 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.

Where have you seen this verb based approach before? Powershell cmdlets.

Windows PowerShell uses a verb-noun pair format for the names of cmdlets and their derived .NET classes. For example, the Get-Command cmdlet provided by Windows PowerShell is used to retrieve all commands registered in the Windows PowerShell shell. The verb part of the name identifies the action that the cmdlet performs. The noun part of the name identifies the entity on which the action is performed.
[Cmdlet Verb Names, MSDN Library]

I’ve written about this aspect of PowerShell before:

In OO, most of the focus is on objects, naturally. However, administrators (i.e. the target audience of PS) tend to be much more task or action focused than object focused. Most OO languages don’t have actions as a first class citizens within the language. C# and Java don’t even allow stand alone functions – they always have to be at least static members of a class.

I’m fairly sure there are many reasons why strongly typed OO languages aren’t popular among administrators. I’m not going to go down the static/dynamic typing rat hole here, but I would guess the object/action language tradeoff is almost as important as the typing tradeoff. What’s nice about PowerShell is that while it has strong object support, it also has strong action support as well. In PS, actions are called Cmdlets. While I’m not a big fan of the name, having first class support for them in PS is one of the things I find most interesting.
[Perusing Powershell Part 1: Get-SQLServer, DevHawk]

While there is no first-class support for verbs or actions in C#, it looks like Anders has essentially rolled his own. For example, his Plan.Event() method returns a new EventDescriptor object. Subsequent calls on this object (RelatedTo, WithPriority, OrganizedBy) change the internal state of this EventDescriptor object. When you reach the end of the chain of calls, EventDescriptor has an implicit EventComponent cast operator that creates a new EventComponent with all the data that’s been collected along the chain by the EventDescriptor.

Again, I can help but think a significant amount of code in this approach can be generalized and the creation automated. Also, I wonder if any of the new C# 3.0 capabilities could be used to improve the implementation. For example, would Extension Methods make it easier to build the fluent interface? Maybe / Maybe not. Regardless, Anders has given me a lot to noodle on.


Morning Coffee 91

  • My wife loves me. I’m a very lucky man.
  • I’m starting to really dig Safari Books Online. Having a tablet really helps here, I can sit in bed and read and it’s ALMOST like reading a real book. Is there an offline experience? Something like the NYTimes WPF Reader app would be killer.
  • I’m not a Twitter guy, but I like the idea of using it to publish CI results. Not quite as cool as using the Ambient Orb, but close. (via DotNetKicks)
  • Soma details the dogfood usage of TFS in Developer Division. Sorta interesting if you’re into knowing that stuff. Brian Harry apparently has much more.
  • I realize that linking to Pat Helland every time he writes something is fairly redundant. If you want his feed, you know where to find it. But he writes great stuff! The latest is Accountants Don’t Use Erasers, which talks about append-only computing. His point that the database is a cache of the transaction log is mind blowing, yet makes total sense.
  • Bruce Payette blogs a PS DSL for creating XML documents.
  • Jesus Rodriguez details WCF’s new Durable Service support in .NET 3.5. I get the need for the [DurableServiceBehavior] attribute, but do I really have to adorn each of the service methods with [DurableOperationBehavior] too? That seems redundant. Also, I wonder how this looks at the channel layer?
  • Speaking of WCF’s channel layer, I recently picked up a copy of Inside Windows Communication Foundation by Justin Smith. This is the first book I’ve found that has more coverage of the channel layer than the service layer, so I like it.
  • Dare writes about Web3S, Windows Live’s general purpose REST protocol. Apparently, WL started with Atom Publishing Protocol, but found that it didn’t meet their needs around hierarchy and granular updates. David Ing says it’s “not that similar” to my concept of REST, but I going to read the spec before I comment.
  • Scott Hanselman writes about how he learned to program and some thoughts about teaching his son. Patrick has recently started expressing interest in programming (he want’s to do what Daddy does). At four, I’m thinking I’ll start him on Scratch (though ToonTalk looks interesting). As he gets older, I was thinking about Squeak, though I’m a smalltalk noob. I really like Scott’s idea of creating a connection to the physical world via something like Mindstorms. Patrick loves Lego almost as much as his dad, so that would be cool.

Morning Coffee 50

  • Nick Carr on net neutrality: “Protocol is neutral. Infrastructure isn’t.” This is a more complicated issue than it appears on the surface.
  • Nick Malik on enterprise architecture: “Enterprise Architecture is not about ‘building solutions right’. Enterprise Architecture is about ‘building the right solutions’.
  • If there had been a good quote on Nicholas Allen’s blog today, then I could declare it “Quote a Nick” day. Alas, his posting on how to respond to GetProperty isn’t very quotable.
  • Hot on the heels of the new GAT CTP is the new Software Factories Toolkit CTP from Clarius. Among other new features is a Recipe Designer. Having mucked around in the Recipe XML, this is A Good ThingTM (via Larkware)
  • Politics 2.0 Watch: Phil de Vellis – the guy that made “Vote Different“, the Hillary Clinton/Apple 1984 video mashup – said he made said video in part because he “wanted to show that an individual citizen can affect the process”. Furthermore, “This shows that the future of American politics rests in the hands of ordinary citizens.” Personally, Bush as Big Brother would have been more appropriate, but I think the video got more attention becuase it cast Hillary in that role.