December 7, 2007
@ 10:01 AM

Microsoft has released a Live Lab's (Microsoft Research and Live Services) preview technology package called Volta.

Volta is a framework that allows a developer to potentially build a multi tier application initially as an client application, and then use a technique called "declarative tier-splitting" to identify which pieces of the application run on a server and which pieces run on the client.

This is accomplished by using and XML like declarative markup within the code. With this approach a developer can focus on getting the application designed and functional and then let Volta split the tiers and create the communications "glue" that lets the applications tiers work together.

How this is accomplished is rather interesting, Microsoft decided to go with an MSIL based approach, mostly accomplished in the post compilation area. MSIL code is rewritten to run in Javascript for the client, and ASP.NET for the server side, typically as a web service.

Since Volta works it's magic at the MSIL level, any CLR targeted language is supported, C#, VB.NET, IronPython and others. Visual Studio 2008 is required at this stage, 2005 is not supported and it is unclear if it will ever be.

So show me some code already!

The code shown below is from the Volta Recipe's page. It shows the [RunAtOrigin] custom attribute in use.

namespace VEMashup.Weather
{
    [RunAtOrigin]
    public class WeatherSvcProxy
    {
        public string GetJsonWeatherInfoFor(double lat, double lng)
        {
            var baseUri = @"http://ws.geonames.org/weatherIcaoJSON";
            var uri = baseUri + "?lat=" + lat.ToString() + "&lng=" + lng.ToString();
            var xhr = new Microsoft.LiveLabs.Volta.Xml.XMLHttpRequest();
            xhr.Open("GET", uri);
            xhr.Send();
            if (xhr.Status == 200)
                return xhr.ResponseText;
            else
                return null;
        }  
    }
}

 

This is an example of "tier splitting" via markup. This tells the Volta framework that this code is destined to run on the server. Code not marked will continue to run on the client. This means that as a developer you can postpone deciding how and where to partition your application until the last minute.

The agile developer in me seriously enjoys this particular aspect! Volta technology is seriously early in the life cycle however, so bear in mind that this will change before it gets released.

There is a handy list of known issues you should review before you start playing with the framework.

You could think of Volta as architecture refactoring on steroids. As shown below Microsoft has designed it explicitly with that in mind. (Image from Volta Web Site.)

image001

Bear in mind that you are not limited to 2 tiers, you can retarget portions of your application to as many tiers as you want!

All in all I think this bears some watching!

Cheers,

Robert Porter


 
Categories: .NET | Agile | ASP.NET | Javascript | Programming | Reviews | TDD | Tools and Toys | VB.NET | Visual Studio | XML


If you write code for a living, no matter what language, flavor, or IDE, sooner or later you begin to develop/write code to a set of unwritten rules that experience has taught you. Sometimes these rules are based on great, hard won lessons, wrested from spectacular failure or success. (Both failure, and success are great learning opportunities.)

Other times they are holdovers from some other project or something you learned from someone else. Or even something you just do but can't explain. My favorite story about the genesis of those kind of rules is as follows.

Child watches Parent making a meatloaf, after the meatloaf is made, Parent takes it out of the pan and cuts about 2 inches off one end and then puts it in the oven. Child ask's Parent why they always cuts 2 inches off the meatloaf? Parent pauses for a moment and says they are not sure why, but their Parent always did that. They decide to call Grand Parent and ask them, Grand Parent thinks for a minute and says it's because their Parent also did the same thing. A quick IM to Great Grand Parent asking why this was done results in the response: "Cause my oven was small and a full size meatloaf would not fit!"

Sometimes, we continue a practice out of habit, not because the need is still there. Most of the time this is fine, but sometimes we unconsciously propagate a behavior or methodology that has lost it's meaning or usefulness over time. Sometimes even to our detriment. It is useful therefor to question why we do things the way we do every now and again. A few moments of introspection can lead to an "Ohhhhh" moment.

I recently experienced such a moment when I was explaining some code I had written to another developer. Once I had finished my explanation they asked me a series of questions about why I did it this particular way as opposed to another. My knee jerk response was "because it's the best way" followed by an unspoken "that I am aware of".

The discussion continued and I soon learned that the method I was using was not only obsolete but was potentially dangerous because of changes in the underlying structure of the language I was using. Changes I was not only ignorant of, but which made a much more robust solution possible.

The method, involving collection classes, that I was using was one I had been using in one form or another for years. I was so comfortable with it, that I had ceased to question it, or look for alternatives. I had developed a blind spot when it came to that particular topic because I was so deep in my personal comfort zone that I subconsciously did not want to move away from it.

This is also an example of the benefit of pair programming, TDD and agile methodologies. To a lessor extent the same results can occur in any team environment. Looked at another way it is an example of why solo developers sometimes do not fare as well. Not having a team to bounce ideas off, or to have question and challenge you on assumptions and approaches can often lead to practices that become bad habits.

That is not to say that all solo developers progress less slowly or that all teams progress better. There are plenty of examples out there of "Toxic Teams" and solo Super Hero coders. But it is nice to be exposed on a daily basis to others points of view, experience and skills. You can derive a lot of the same level of benefit, albeit less interactively, by reading blogs, and participating in development forums all over the net.

But every now and then, solo or team member, you should stop, reflect, and refactor your own thinking process and assumptions. Weed out the things that no longer work for you, and try and replace them with things that do. Learn something new, test it against your own experience, if it seems to fit consider making a new habit to replace an older one!

Cheers,

Robert Porter


 
Categories: Agile | Programming | Ramblings | TDD


I was recently refactoring some code in a Web Service that is called by numerous external consumers as well as internal clients. As we all know when you publish an interface you are more or less signing a contract not to change that interface. This becomes even more of an issue when clients outside of your organization are calling your code.

Or perhaps you have written and distributed an SDK or API that is used by others to access functionality in your application. Either way, you change such public facing interfaces at your peril! It's why you often see method names like the following in public SDK's:

ShinyMethod
ShinyMethod2
ShinyMethod3
NewShinyMethod

This results from having realized, after the fact, that your public interfaces were unable to do something you want/need them to. Or perhaps something you are calling changed and now you need more information or different parameters than before. Whatever the reason since you signed the contract, you had to implement different methods leaving the old ones intact so that you don't break every caller instantly during your next update.

This is a legitimate response to a common problem. Now don't start screaming at me about better design, overloading methods etc. I know there are dozens of ways to tackle issues like these. I am using this as an example about how to notify your callers that you are about to "renegotiate" your contract in a gentle kind manner!

So, let's say you have a method, called MyShinyMethod that takes two integers and a string as parameters. For 6 months or so that method has sufficed to handle it's intended function. Then one day you get a call from accounting telling you that now you need to handle two integers, 1 string and a double! Ah, you say, no problem and add an overload to your method.

Then, sometime later accounting and marketing call, now the calling programs need to be able to pass 2 doubles, 3 strings, and a boolean and return an XML file.

Ok, you see where this is going, you really can't continue to handle this with overloads, and what you really want to do is change your public interface. But you can't do that, at least not immediately. So we need a way to tell all our callers that we are going to change our interface. In comes the "Obsolete" attribute.

You build a new version of you service, with the existing public methods you had, and you add a new even shinier method called MyNewShineyMethod that is designed to take just about anything and return even more!

Now we need a way to notify existing clients that there is a new method in town, and that the old method will soon be leaving!

Your old method would look something like this:

Public Function MyShinyMethod(ByVal int1 As Integer, ByVal int2 As Integer, ByVal str1 As String) As Boolean
     'do something cool here
     Return True
End Function

 So now you add your new method, and need a way to tell your callers that they should start to use the new method, and get ready to stop using the old one:
 <Obsolete("This method is not so shiny anymore, start using: MyNewShinyMethod")> _ 
Public Function MyShinyMethod(ByVal int1 As Integer, ByVal int2 As Integer, ByVal str1 As String) As Boolean
'do something cool here
Return True
End Function
Public Function MyNewShinyMethod(ByVal params As Collection) As String 
'do something cooler here
Return ""
End Function

Now when users compile their applications that call your service, they will get a warning error if they are using the old version with the text you supplied with the Obsolete attribute. They can still compile run and call the method, but they will begin to see the "error of their ways" in the form of compiler warnings.

Now, eventually you want to be able to "retire" the not so shiny method. Change the attribute as shown below, and instead of warnings, the caller will get Errors!

 <Obsolete("This method is no longer available, use: MyNewShinyMethod instead.", True)> _ 
Public Function MyShinyMethod(ByVal int1 As Integer, ByVal int2 As Integer, ByVal str1 As String) As Boolean
'do something cool here
Return True
End Function
Public Function MyNewShinyMethod(ByVal params As Collection) As String 
'do something cooler here
Return ""
End Function

By adding the "true" parameter we are telling the IDE in the calling applications to flag this as an error and not allow compilation. But the error message shows the caller what to use instead!

Hope this helps!

Cheers,

Robert Porter


 
Categories: .NET | Agile | Programming | Visual Studio


I ran across a nice article by Mark Seemann on MSDN. It was published in the September 2007 issue of MSDN Magazine. In it he covers what he describes as the continuum relationship of Mocks, Dummies, Stubs, Spies and Fakes in Unit Testing.

The following diagram is from his article to illustrate the point:

Implementation Coverage

As you can see, each component has varying levels of implementation depending mostly on your needs etc. The article is worth a read!

Cheers,

Robert Porter


 
Categories: Programming | TDD | Agile


September 23, 2007
@ 10:39 AM

I would have to say that I have become a convert to TDD concepts. I have used NUnit, and mbUnit testing frameworks to varying degrees for some time. Now I use them daily and am working to increase my coverage in all my projects.

Since I primarily develop in the .NET Framework I have particular interest in the unit testing frameworks available in that environment. As I mentioned in a previous post I have currently settled on mbUnit as my unit testing framework.

xUnit is a new framework developed by, among others, James Newkirk and Brad Wilson. James was one of the original authors of NUnit and is now a Microsoft employee. Brad Wilson also works for Microsoft. Together they have created what looks to be a very well thought out testing framework.

xUnit is currently being hosted on CodePlex and is distributed under Microsofts Permissive License (The borgs version of Open Source).

The framework has already been integrated with TestDriven.NET, and has it's own console runner, but no GUI runner yet.

Roy Osherove has a series of posts about his view on xUnit, and both James and Brad have blogged about it as well. The first post of interest to me was this one, then check this one.

After reading all the various points of view on this topic here is what my take away is so far. xUnit is a conscious choice to re-invent a testing framework that is not just another port and extension of JUnit. It features design changes to bring it more in line with where the .NET Framework is, and is heading. Examples of this are the use of Generics and Anonymous Delegates in Asserts.

They have also removed a great number of what they consider extraneous attributes see the quote from James post below:

    • [TestFixture] was removed entirely, so tests can be anywhere.
    • [Ignore] is expressed using the Skip= parameter on [Test].
    • [SetUp] and [TearDown] are removed.
    • [ExpectedException] was replaced with Assert.Throws.
    • [TestFixtureSetup] and [TestFixtureTearDown] are instead expressed as implementations of an interface (ITestFixture).
    • Support for IDisposable was added for tests.

This kind of thinking and approach is long overdue in my own opinion. It will be interesting to watch as the project matures. I have begun playing with it myself and so far I find it a lot more intuitive than any of the JUnit derivatives I have used in the past.

While I like mbUnit I have always had to think harder than I feel I should in order to use it. I get results that are often exactly opposite what I was expecting, which means that I am obviously not understanding something. It is also difficult to get help with mbUnit, while it is not abandonware it does not have a very active community, posts to their list server often go unanswered for long periods of time. And the Google Group discussion forums are none to active either.

Time will tell if xUnit suffers from the same lack of community or not, but so far it looks promising! 

Cheers,

Robert Porter


 
Categories: .NET | Agile | Programming | Reviews | TDD


January 2, 2005
@ 12:41 AM

Hmmm