Friday, 22 February 2008

Vista SP1

I installed Vista SP1 on my PC at home earlier this week. It took an hour to install.  I didn't notice any obvious improvements or changes at first. Perhaps it boots a bit faster now, but that kind of thing is very subjective unless you have bothered to time it beforehand.

However, yesterday I found the first real improvement. I had been having problems saving my game in Football Manager 2006. It would take several minutes to save the 200Mb file and would regularly fail to save. Sometimes I would have to attempt to save the game 5 times in a row before it would work. The good news is, that since installing Vista SP1, I have had no errors saving, and the saving is much, much faster (less than 30 seconds now). Its always nice to see some kind of tangible improvement after installing a service pack.

Friday, 15 February 2008

There is no Spoon

And now since I'm in the mood for writing some XAML, here's something really silly. My 2 year old son always throws his spoon in the bin along with his empty yoghurt pot, which has meant we are regularly buying more spoons. So here is a really useful XAML "No Spoons" sign for the bin. I 'designed' the spoon icon in Blend, and then used a transform group to get it into the right place.

Here's the code:

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <Canvas Canvas.Left="20" Canvas.Top="20">
    <Rectangle Width="180" Height="200" Fill="White" RadiusX="5" RadiusY="5" />      
    <Canvas>      
      <Path Fill="#FF000000" Stroke="#FF000000" Data="M438.66803,130.33333 C421.33499,120.1762 422.00165,96.176278 422.00165,96.176278 427.00179,58.843133 452.66745,63.333794 460.00086,94.666778 461.00102,116.50951 455.41396,118.92027 446.00105,130.00013 L450.41981,208.7423 C446.16375,210.81869 441.91328,210.84422 437.66793,209 z" StrokeThickness="2"/>      
      <Canvas.RenderTransform>      
      <TransformGroup>      
      <TranslateTransform X="-350" Y="-60" />      
      <RotateTransform Angle="-45" CenterX="100" CenterY="100" />      
      <ScaleTransform ScaleX="0.75" ScaleY="0.75" />      
      <TranslateTransform X="25" Y="15" />      
      </TransformGroup>      
      </Canvas.RenderTransform>      
      </Canvas> 
      <Canvas Canvas.Left="10" Canvas.Top="10">     
      <Ellipse Height="150" Width="150" Stroke="Red" StrokeThickness="15" />      
      <Line StrokeThickness="15" Stroke="Red" X1="25" Y1="125" X2="125" Y2="25" />      
    </Canvas> 
    <TextBlock Canvas.Top="160" Canvas.Left="30" Text="No Spoons" FontFamily="Arial Black" Foreground="Black" FontSize="20"  />     
  </Canvas>      
</Canvas>

And here's what it looks like:

image

XAML Star Rating

And here's another quick XAML file, this time for star ratings like you see on many websites. By the way, I've been fighting with blogger to try to display code nicely, but it seems to insist on truncating it, and ignoring any styling I try to put on it. I'm hoping to move to another blog platform before too long, but if anyone knows of a simple way to make blogger display formatted code, please let me know.

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <Canvas Canvas.Left="20" Canvas.Top="20">
    <Rectangle Width="200" Height="50" Fill="White" RadiusX="5" RadiusY="5" />
    <Canvas Canvas.Left="5" Canvas.Top="20">
      <Path Stroke="#000080" Fill="#FFFF00" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" />
    </Canvas> 
    <Canvas Canvas.Left="45" Canvas.Top="20">
      <Path Stroke="#000080" Fill="#FFFF00" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" />
    </Canvas>
    <Canvas Canvas.Left="85" Canvas.Top="20">
      <Path Stroke="#000080" Fill="#FFFF00" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" />
    </Canvas>
    <Canvas Canvas.Left="125" Canvas.Top="20">
      <Path Stroke="#808080" Fill="#C0C0C0" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" />
    </Canvas>
    <Canvas Canvas.Left="165" Canvas.Top="20">
      <Path Stroke="#808080" Fill="#C0C0C0" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" />
    </Canvas>
  </Canvas>
</Canvas>

And this is what it looks like:

XAML Star Rating

XAML RSS Icon

I haven't had the time to blog much recently, but I thought I would just share a quick RSS Icon I made in XAML recently:

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
  <Canvas Canvas.Left="20" Canvas.Top="20">
    <Rectangle Width="50" Height="50" Fill="Orange" RadiusX="5" RadiusY="5" />
    <Canvas Canvas.Left="-1" Canvas.Top="1">
      <Ellipse Width="10" Height="10" Fill="White" Canvas.Left="10" Canvas.Top="30" />
      <Path Stroke="White" StrokeThickness="5" StrokeStartLineCap="Round" StrokeEndLineCap="Round" Data="M 15,20 a 15,15 90 0 1 15,15" />
      <Path Stroke="White" StrokeThickness="5" StrokeStartLineCap="Round" StrokeEndLineCap="Round" Data="M 15,10 a 25,25 90 0 1 25,25" />
    </Canvas>
  </Canvas>
</Canvas>

Here's what it looks like:

XAML RSS Icon

Obviously if you are a graphic designer you could give it some cool gradient effects to make it look 3D.

Tuesday, 22 January 2008

Refactoring Windows Forms

I have been attempting to refactor some Windows Forms classes that contain hundreds of controls and have thousands of lines of code behind. What I would like to do is to group a load of controls together and make a new UserControl that contains them. The only trouble is, there seems no easy way to do this. None of the refactoring tools seem support it, and if you were to simply try to cut and paste the controls using the Windows Forms designer you would end up losing all your event handlers and potentially messing up the relative positioning of all your controls (lots of docking and anchoring is going on).

My approach in the end was to make a complete copy of the entire class in question and delete parts from it. Then I have spent two whole days trying to reduce the compiler error count to zero (I'm down to just 19 now from 387). Even so I now have a whole bunch of event handlers that need to be hooked up and a horrible feeling that my new panel will not quite work exactly like the old one did.

So what's the point of this post? Well just to say, wouldn't it be nice if one of the .NET refactoring tool companies would implement this? Allow you to select a bunch of GUI components on a form to move to a new UserControl, expose the appropriate properties and events, and hook up the old code to access the new control. Obviously you would want to perform more refactoring after doing this, to clean up the interface to your new UserControl, but it would be an invaluable tool in managing Windows Forms projects that have got out of control.

Saturday, 1 December 2007

Silverlight 2.0

Most developers with an interest in Silverlight will already know that 1.1 is being rebranded 2.0 and that we have more details about what it will include thanks to ScottGu's announcement.

The change of version number makes a lot of sense. The inclusion of the .NET framework is hardly a minor upgrade. It was the announcement of Silverlight 1.1 that got me interested in Silverlight in the first place. I had no great desire to learn how to do everything in JavaScript that I already knew how to do in C#.

It looks like they're planning to add quite a lot more features in the next beta drop. Most importantly, they are providing controls like textboxes, checkboxes, radio buttons. Also we get more than just plain old Canvas for layout - we get grids and stackpanels. There are even progress bars, sliders and a GridView. This is great news. We will be able to focus on the behaviour of our applications rather than writing custom controls.

Even more impressively, it looks like they are bringing a lot more of the core functionality from WPF such as data binding and control templates in. This means that Silverlight could actually become a serious competitor to WPF in its own right.

The networking support has been enhanced, with the most notable improvement from my perspective being the ability to access resources from other domains, removing a rather awkward limitation  from the alpha release.

Finally, Scott hints at even more of the FCL being made available, with a particular improvement to the DOM integration. I'm guessing that all this means that the size of the installer for Silverlight 2.0 will have grown a bit. I want to go on record as saying I don't care. I think its absolutely amazing how much they have crammed into such a small space, but the more they put in there the better as far as I am concerned. 

There are only two disappointments for me. First: apparently we have to wait for this until the new year. Fair enough I suppose, as there is a lot of new stuff coming. But it does mean that if like me you have projects that use controls, then you may want to hold off until the beta is released to save you wasting time re-inventing the wheel.

Second, although they are planning to support Silverlight development in the Express editions, we must wait until next summer. Which is annoying for me, as I like to experiment with Silverlight at home. Still, I can't complain too much, as Silverlight 2.0 isn't even in beta yet, so I suppose I should cut them a bit of slack.

Anyway, credit to whoever at Microsoft thought up Silverlight 1.1/2.0. I think it's one of their best innovations since they came up with the idea of .NET in the first place.

Thursday, 29 November 2007

Productivity and Enthusiasm

During my holidays in my first year at university I did some warehouse work to earn some extra cash. My job involved offloading pallets of food from lorries using hydraulic pallet jacks and depositing them down a ramp from which the fork-lift truck drivers would collect them to stack in the warehouse.

Now when a lorry came in to be offloaded, there was nowhere to hide. Whether I was feeling full of enthusiasm for doing my job or bored witless, I still had to get to work. The net result was that whether my "enthusiasm" (E on the graph below) was low or very high, my "productivity" (P on the graph below) didn't vary that much.

Productivity versus Enthusiasm for manual labour

What's this got to do with software? Well, the following years I started doing programming as a holiday job, and went on to become a full-time computer programmer. But I soon noticed that in the world of software development, my Productivity versus Enthusiasm curve was radically different.

Suppose I come into work feeling tired and the task I have been given to do is not an enjoyable one (e.g. fixing elusive bugs on a legacy product, or adding a pointless feature to please marketing, writing documentation). In that case I find that a day can easily go past where productivity is close to zero.

On the other hand there are days when I am feeling very enthusiastic about my work. Perhaps it is because I am learning and using some new and interesting technology, or perhaps I am refactoring some badly designed class into a really elegant and simple structure. In this case I find that my productivity increases exponentially. As long as I am not interrupted by distractions, in this state I can become super-productive, fixing bugs and churning out new features at an incredible rate.

Productivity versus enthusiasm for software development

Why the difference between the two graphs? Why could I get work done at the warehouse on low enthusiasm days, but not in the world of software development? The answer is simply that to write software requires concentration and concentration requires interest. At the warehouse I could offload lorries while thinking about all kinds of unrelated subjects. But to write code, my mental focus must be entirely on the task at hand.

If this is true, then the way to maximise productivity is to minimise boredom. If we recognise the things that capture our interest and enthusiasm, we can design development strategies that promote productivity.

This is I think part of the genius of the "agile" approach to software development. Running tests manually is boring, but writing automated tests is much more intellectually stimulating. Bug-fixing is boring, but refactoring code to improve its design while you fix a bug gives a real sense of achievement for a developer who takes pride in their work.

I don't expect boredom can ever be completely eliminated, and so there will always be the need to grit your teeth and show some professionalism. But the route to increased productivity in software development is more closely tied to motivation and enthusiasm than many of our managers seem to appreciate.