Ovechkin as Superman

Just saw this over on Japers’ Rink and had to share. This video won a three 2007 Golden Matrix award from the Information and Display and Entertainment Association (IDEA): Best Music Video, Best Overall Video Display (hockey) and Best Overall Video Display (overall). More details on Kukla’s Korner. Congrats to the Caps PR team.

Next season is only a little under three months away. Given the moves the Caps have made this off season, next season should be a sight better than last season. Playoffs? Maybe. Contending for playoffs? Probably? Cup Contenders? Check back in a couple more years!

Morning Coffee 101

  • In doing a little LINQ research, I stumbled upon Wes Dyer’s Yet Another Language Geek blog. Fascinating stuff. Subscribed. Be sure to check out his recent posts about Partial Methods, another new C# 3.0 (and VB9) language feature.
  • Werner Vogles has a great post on what a CTO does, including a summary of four different approaches to the job.
  • Somasegar lets us know that even though VS08 doesn’t launch until February of next year, MSFT is “still aiming to release Visual Studio 2008 and .NET FX 3.5 by the end of this year”.
  • There’s a new version of the Windows Live Mobile Search client. The Virtual Earth / Live Search team blog has the details. New features include Movie Showtimes, More Local Data with Reviews and improved Maps and Directions (including GPS integration). Can’t wait to get this installed. (via Dare Obasanjo)
  • XNA Gamefest is coming up next month. It’s sort of like PDC for game developers. It’s where we make our big game dev announcements – last year, we announced XNA GSE there. They recently published their session abstracts, including a whole track on XNA Game Studio Express. As Shawn Hargreaves points out, an “enterprising reader could probably make a good guess” about some of the new stuff getting announced @ Gamefest.

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 100

  • The big 100. This puts be 1083 posts behind Iron Link Poster Mike Gunderloy. As his .NET skills deteriorate, maybe I can catch up…but I doubt it. I’m only 77 posts behind Sam Gentile, so maybe that’s a bit more feasible.
  • The ADO.NET Team blog announces the new Entity Framework CTP. Looks like there’s also a new .NET Framework 3.5 CTP and new Visual Web Developer “Orcas” Express CTP as well. (via Sam Gentile)
  • Speaking of “Orcas” VS 2008, it launches with Windows Server 2008 and SQL Server 2008 next February. (via DNK)
  • Scott Guthrie continues is LINQ to SQL series. This time, using LINQ to SQL to update the database.
  • My friend Arvidra Semhi recently moved and rebooted his blog. Among his many accomplishments, Arvindra started the Architecture Journal. I’m particularly interested in his recent Service Capsule work. Subscribed.
  • Last night was the Microsoft E3 Briefing. Gamerscore blog has the news rundown. Didn’t seem to be any HUGE news. Last year’s E3 was the first Halo 3 showing and X06 featured the Halo Wars announcement. Nothing that earth-shaking this time, though the XBLM keeps on rolling, now featuring Disney movies. (Major Nelson has a list.) I’m thinking that the whole HD-DVD vs. BluRay war is going to be eclipsed by direct download before it’s over, though I’m still waiting for PC support & all-you-can-eat pricing.
  • Politics 2.0 Watch: Clay Shirky has a great blog post on modern-day Luddites. As he points out: “A Luddite argument is one in which some broadly useful technology is opposed on the grounds that it will discomfort the people who benefit from the inefficiency the technology destroys.” How much inefficiency is there in our modern political system? And more importantly, who benefits from that inefficiency? We’ve already seen the dramatic effects blogs can have on political news, media and reporting. What happens when users citizens are no longer satisfied just writing about the political process and want to get their hands dirty in the policy-making process itself?

Restating the Concurrency Problem

I’ll be honest, I recommended Herb Sutter’s concurrency series in today’s Morning Coffee because it a series on concurrency by Herb Sutter. In other words, I hadn’t actually read it yet, but I know how good Sutter’s stuff is. Now I have read it and I wanted to re-issue my recommendation, even more strongly. Go read it.

Interestingly enough, I like the article because it doesn’t provide an “answer” to the problem of concurrency. Rather, by providing a mental model, it essentially is a concise and precise restatement of the problem. Often, in the rush to find a solution to a problem, this step is skipped and it isn’t until the end that you realize that you misunderstood the original problem and what you built doesn’t match what you need.

I’ve often argued that this is also the key to selling in the enterprise. In my experience, whatever solution you’re selling is usually way too complicated to be understood by the people who have the purchasing power to buy it. So explaining how your solution works or how your solution solves the problem isn’t going to get you very far. However, the buyer does understand the problem at hand. Being able to demonstrate that you understand the fundamental nature of the problem and can communicate it back to them garners you a great deal of trust in the selling process. If you can show that you understand their problem, then you probably know how to fix it – even if the buyer doesn’t understand how your solution works.

One other quick thought on Sutter’s article. In discussing the use of concurrency to keep a GUI responsive (aka Pillar 1), he wrote the following:

Today, we typically express Pillar 1 by running the background work on its own thread or as a work item on a thread pool; the foreground task that wants to stay responsive is typically long-running and is usually a thread; and communication happens through message queues and message-like abstractions like futures (Java Future, .NET IAsyncResult). In coming years, we’ll get new tools and abstractions in this pillar, where potential candidates include active objects/services (objects that conceptually run on their own thread, and calling a method is an asynchronous message); channels of communication between two or more tasks; and contracts that let us explicitly express, enforce, and validate the expected order of messages. [emphasis added]

If we’re going to provide the ability to express, enforce and validate the expected order of messages between concurrent blocks of code, can we also do it for services across the network? WSDL is wholly deficient in this area. SSDL’s Communicating Sequential Processes (CSP) and Rules-based Protocol Frameworks are a good start.