Real use of Microsoft Oslo?

How would you use Oslo in the real world? Well, this weekend I got a little Oslo “infection”. For the moment, only with Intellipad tool.
Working with MSpec and with BDD style tests, I always thought that a really good thing would be to generate test’s code or to run somehow tests specified in plain English, not only to see them nicely organized (although, that’s a very helpful thing).
How about writing some BDD style plain English statements, obtain a MGraph from it with a help of an MGrammar, get some expression trees (there are some ways to get CLR objects from that MGraph, with help of Xaml or with some serialize/deserialize helpers or with some graph traversing techniques), compile and run? That could be a real use, allowing clients and business analysts to work directly on specifications. I wasn’t surprised to see that there are already some grammars which can parse that syntax (MisBehave, for example).
Let’s think of an other example, starting from a simple scenario… I have an WPF login demo application. Its specifications/business rules are stored in code. How about get them out from code and being able to modify in plain English? Something like that:

If MyLogin Attempts is greater than 3
Then Message should be ‘Sorry, too many tries already’.


If MyLogin Attempts is equal with 2
Then Message should be ‘One more try!’.

Enter my very first MGrammar:

MyLogin Oslo

I successfully got then LoginRule objects with the help of Xaml (see Person example from msdn) after I modified the projection to look like this:

syntax Rule = "If MyLogin Attempts" o:Operator a:Attempts         
"Then Message should be " m:Message "."
=> LoginRule { Operator => o, Attempts => a, Message => m};

And the LoginRule is my custom object which knows if it has to apply itself or not to my LoginViewModel and, if yes, it set the proper error message.

That’s of course a very limited example but shows (perhaps) some real uses of Oslo.

So, Oslo is not only about data. Since we can transform back and forth code into data, behaviors into data then we can store them in Oslo Repository, we (in fact, the clients) can edit them in a kind of English language and run them as code when needed.

For next releases I expect Microsoft to provide a clearer way to get objects from graphs (perhaps Spring.NET or Castle can help here, too but I didn’t wanted to dig further since I can work for the moment with Xaml way to get objects).

Am I just tired and talk nonsense?

Here is the test grammar used to parse these simple behaviors:

 

//Login Demo with Oslo
module MyLogin {
    language LoginLogic {

        syntax Main = Rule*;
        syntax Rule = "If MyLogin Attempts" o:Operator a:Attempts
            "Then Message should be " m:Message "."
                => LoginRule { Operator => o, Attempts => a, Message => m};

        token Attempts = "0" .. "9";

        token Message = "'" ("a".."z" | "A".."Z" | " " | "," | "!")+ "'";
        token Operator = "is greater than" | "is equal with";
        interleave  Whitespace = " " | "\r" | "\n";
    }
}
emipasat posted at 2009-10-5 Category: Development/Programming | Tags: ,

One Response Leave a comment

  1. #1Bogdan Ungureanu @ 2010-12-28 16:12

    Have you considered taking a look at Boo? http://boo.codehaus.org/
    Also http://www.manning.com/rahien/
    And Fowler – Domain Specific Languages

Leave a Reply

(Ctrl + Enter)