Pete Wright's Radio Weblog
Musings on anything and everything, but mainly code!

 

 

04 June 2004
 

Microsoft say NO to Pirates!

For years now Microsoft has effectively supported pirates. When I say supported, I mean that in a techie sense. Regardless of whether you bought their software or stole it (I'm sorry, I should say "shared" it) you could still go to www.microsoft.com and download updates and fixes. As the crackers stretched the Microsoft OS's more and more, and discovered more and more loopholes, Microsoft's teams at Redmond worked tirelessly to deliver patches to the valid user community as well as to those who had paid not a one cent to run the software in the first case.

No more though. According to the BBC online new code in the long awaited SP2 upgrade to XP will check to see whether you are using one of the hundreds of thousands of illegal copies of Windows XP. This is fairly easy to do, since most widespread piracy of the operating system actually stems from just a handful of OS ID's. The code checks the ID of the installed version of Windows XP and will refuse to download the upgrade. This means security holes will go unplugged, illegal users will not benefit from the improvements in SP2 for managing firewalls and virus software and a whole bunch of goodies besides.

You never know, but if you really think about it this could the most move towards making piracy really socially unacceptable. I know that in reality this is impossible, but just imagine a world where you can spot the thieves and spongers of the world a mile off easily. They would be the ones saying "Oh no, I think I got a virus!"

 


11:36:09 PM    comment []

The not-so-obvious benefits of Test Driven Development

I've been working my way very rapidly through Extreme Programming Adventures in C#, from Ron Jeffries and I've noticed some very subtle benefits to the way Ron does things. I mentioned in a previous blog post that Ron's book has a narrative style that leads you hand in hand with him as he applies eXtreme Programming practices to a new project, while simultaneously learning C#. It's the geek equivalent of "And now ladies and gentleman, for your delectation, a triple forward somersault blindfolded over a pit of crocodiles without a safety net".

The thing you notice almost as soon as Ron starts to write code is that he uses Unit tests not just to test required functionality in methods, but also to try out ideas. For example, if I were struggling with putting an XML feature into my application, Ron would advocate writing a test that explores the functionality of .NET's XML support, like this

[Test]public void FindNode()
{
	string xmlConfig = @"<courier><machines/></courier>";
	XmlDocument configDoc = new XmlDocument();
	configDoc.LoadXml( xmlConfig );
	XmlNode node = configDoc.DocumentElement.SelectSingleNode("machines");
	Assert ( node != null );
	Assert ( node.Name == "machines");
}

It's not immediately obvious but this is a very cool way of working for a number of reasons. First up, obviously it saves you all the hassle of creating hundreds of dinky throw away test projects. Second, using nUnit to test your own assumptions about how the part of the framework you are learning works gives you a very visual, and immediate feedback loop which is  a great aid to learning. Third, despite all the online help that Microsoft kindly provided with Visual Studio.NET, it can still be hard to find just the right code example for the job. Since you most often create these little technology tests as I can them to solve a specific problem in your code, you start to build up a repository of research right there in your app solution with fully tested working code that shows just how to get things done. I can't count the number of times now that I have cut and pasted code from the technology tests into the main project classes (and then refactored it of course, to remove duplication) when I've run up against a wall.  The final benefit of this way of working is that these technology tests, if you add them to a single TestFixture class in chronological order provide a wonderful insight into the train of thought your went through when building the application. I don't know just how useful that is yet, but it sure is a neat free win.

On a different note, its really easy to adopt misconceptions about test driven development. The most common of these is that you spend so much time developing the tests at front, compared to the amount of time that it takes to get the feature in question working, that unit tests would appear to be detrimental to the progress of your work. Don't you believe that one for a second. Sure, writing the actual feature code usually burns a lot less time than the unit tests around it, but would that be the case if the unit tests weren't there. Think about it for a second. Your unit tests, written before you added the funtionality itself, test the code and provide valuable insight during the feature's development as to what's not working and why. Without that feedback I can't help feeling that you'd get the feature code written just as quick, but debugging it could degrade into a nightmare. When that happens there always a resistance to move on and just record the bugs for later. Unit tests get you to the same point in time that you' d  normally say "It's good enough" with code that is perfect and not a compromise based on time.

By far the biggest benefit of unit tests though, in my opinion, has nothing to do with checking that the code works. It has to do with providing a safety net that enables refactoring and code evolution. We all meet those points in writing an app where something needs to be restructured. Whether you call it optimizing, refactoring, hacking or tweaking, the fact remains that without a set of unit tests underneath your code base you have no real idea whether or not all your hard work is actually damaging the application as a whole. Those unit tests that were so tedious to write when you were itching to add a new piece of functionality really come into their own when you need to tweak stuff. They tell you when you screwed up and where. That's invaluable.

Unit Tests then are an investment on three levels; your knowledge, your application's stablity, and your applications future, unplanned and unimagined evolution.

 

 


9:44:39 PM    comment []

Visual Themes in VS.NET 2003? I didn't know that!

About one of the first things I did when I got Visual Studio.NET 1.0 installed on Windows XP was create an application hoping to see it automatically adopt the subtle curves and soothing blues of XP's default theme. Obviously, it didn't work. Visual Studio.NET 1.0 didn't support themeing of rich Windows Forms user interfaces. In order to theme an app you had to produce a nasty manifest file and wedge it inelegantly into the final deployed application.

I should have known better, but when I got VS.NET 2003 I did the same thing. Surely after XP being out for a considerable amount of time Microsoft had to have built them support in. Alas, the default look and feel of apps from VS.NET 2003 also lacked theme support. I heard a rumour that changing the Flatstyle property of the controls on a form (which you have to do when working with themeing manifests) to System would help, but alas that was also a dead end.

I had a long train journey to a from a client today and that gave me a great opportunity to dive into some MSDN magazine issues that I hadn't scoured in full before. In one I came across a piece from Chris Sells talking about all the sexy features in VS.NET 2005. Among them was theme support, which Chris summed up with a history. I nearly fell off my chair when he pointed out that theme support is indeed included in VS.NET 2003, they just made it better in 2005.

To turn on theme support in your applications just make a call to Application.EnableVisualStyles() before your main() function makes it default call to Application.Run(). You still need to manually make sure that all the FlatStyle properties of your controls are set to System (something Chris says VS.NET 2005 does automatically), but the results are well worth it, as you can see.

Compare and contrast the two screenshots. The themed app has nice subtle borders around the controls, curves on the buttons, lovely subtle shading on buttons. It's just gorgeous. Well ok, maybe not, but it's a damn sight easier to achieve in VS.NET 2003 than I thought it was. How I missed this one I don't know.

 

 


9:44:26 PM    comment []


Click here to visit the Radio UserLand website. © Copyright 2004 Pete Wright.
Last update: 01/07/2004; 16:45:12.
This theme is based on the SoundWaves (blue) Manila theme.
June 2004
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
May   Jul