I've been trying to get my head around "M" and "MGrammar" and "Oslo." I put the names in quotes as I'm not sure what's a codename and what's not. ;)
Oslo Developer Center on MSDN - The hub of all things "Oslo"
I had an opportunity yesterday to do a SharedView with Doug Purdy on his Mix talk. The talk is Developing RESTful Services and Clients with "M" and it's Friday at 9. He'll be doing it with Chris Sells as Code Monkey. Doug and Chris are an animated pair and their talks are a hoot.
When I've seen Oslo talks before, it's seemed like a lot of hand-waving and talk of things transforming into SQL and magic and elves. I told Doug it was too high level and that'd I appreciate something really concrete that I could really start to grok. So he focused on "M" - their new modeling language. I've done some simple DSL (Domain Specific Languages) so I figured this would be a good place to start.
Also, I took a bunch of screenshots (secret - don't tell!) while I was in this LiveMeeting/SharedView of Doug's demos. This part is making sense to me.
Here's a screenshot of their editor. Don't sweat the tools too much, but it's basically Emacs with a .NET heart written in WPF using IronPython for plugins. They call it Intellipad. You can do this stuff from the command-line, though. It's lightweight and quiet.
NOTE: The Intellipad editor is using the same WPF Editor in Visual Studio 2010. Nice to see folks sharing components. How is it all plugging together? MEF. Bam!
Anyway, on the left there, is a sentence "Scott is 36 years old." Actually my wife says I'm 35, so my bad there. Anyway, that sentence is a DSL - a Domain Specific Language. It's a DSL only because we decided it was. Just now.
In the middle there is the MGrammar (in a .mg file). (Good video on MGrammar here)
This is kind of like Lex and YACC, but more general, and it quickly gets away from the dirty text parsing part of things and into the model much faster than they do.
The MGrammar in the middle describes our new DSL for expressing info about People. I can now say "Fred is 12 years old..." etc. Now I've got a simple DSL that I can consume and anyone can right. Still, a DSL isn't useful unless you can DO something with it.
On the right, in the third window pane is a tree of the output of this DSL with the MGrammar applied. Now I've got an object (or series of them) with properties that I can do something with.
Now, we could give the system more info about these People. Like, give them an Id that's an Int32, make sure the system knows Age is an Int32 also, etc. There's all sorts of constraints like this that are much richer than a DB. This is the "modeling" part. We express what something is as simply as possible.
OK, so fast forward and switch gears to something more concrete. You're probably familiar with cURL. It's
a the command-line tool for messing with URLs from the command line. You can GET, POST, etc with this nice command-line tool.
They created an example they're calling MURL to show how one could create a Domain Specific Language for talking to URL endpoints. Stated differently, MURL is a REST client built with their tools in very little code.
In this shot, he's got the MURL DSL on the left, looking like HTTP initially. Just GET url, for now. Then he adds to the language and makes it so he can do things like "secure using" with names and passwords. Then he adds POST support with payloads, etc. He can make his little language look like whatever he wants.
In this screenshot, he's made ? mean GET and ! mean POST, etc.
Some DSLs we use all the time are:
- SQL - "select * from whatever"
- XPath - "//something/else[@cool = 'neat']
- RegEx - "%(&^%&^$#%#$@#$*@#((**$#$%"
And we often use these DSLs and their associated "engine" from our .NET code. That means, I could use MURL (or any other DSL and its engine I create) from my existing .NET code.
See the "runtime.Parse" statement in the screenshot below? I'd probably change the name and make it a one liner like "Murl.Do()" but you get the idea. Then the result is just XML I could go to town on.
Here he's using his MURL language from inside ASP.NET MVC to do some work. Don't get mired in the fact that he's just doing an HTTP GET to an endpoint. You might be all (and I was too) "ya, I can use Web Client for that." The idea would be you could create languages that can more easily expressed in a DSL than in C#.
When I worked in banking (not too long ago, actually), Patrick and I created a DSL for modeling domain object by extending XSD (an existing DSL). We could have created a much more terse and person-friendly DSL (as opposed to XML which is person-hostile) with tools like this. I can see this greatly facilitating Domain Driven Design.
Doug's talk is at Mix (and will be online later) on Friday and you can find it on the Mix Site. Remember it's not really about URLs, or REST, or MURL, it's about the creation of DSLs and the tools that support it.
It's early, but now I've got more context. I'm not on board yet, but it's slowing sinking in for me.
Other MGrammar Examples