A Symphony of WAT

I’ve just started a unit at University called “Desktop Application Development” which is supposed to give students “an understanding of the processes and techniques used to develop end-user software that includes modern graphical interface components” and “practical experience in constructing desktop applications within an advanced software development environment”. In this case the framework of choice is WinForms via C# and the IDE is Visual Studio 2010.

It all sounds quite reasonable – and for the most part,  it is. The lectures have been good thus far and I’m interested to see what will be discussed later in the term. However, the coursework is a different matter entirely and while the concept seems solid, I feel very strongly that the implementation just isn’t suitable for the course.

Concept

The practical component of the coursework is to develop an image library application which has a simple file-based database of collections and information about the photographs each record points to. I feel this is a good coursework task because:

  • it requires implementation of file IO
  • the end application will be fairly complex, making use of multiple windows and dialogs (including custom and common dialogs)
  • the final product should be useful in some way
  • the final product can be extended to add extra features.

However, with the good out the way, now we get the the weird…

The Weird

Rather than getting students to start from scratch, a project is provided as a starting point, with the main form already populated with the required controls and even some predefined methods. Three other dialog forms are also included (similarly pre-populated) along with complete classes for handling images and image collections.

At first I was really surprised by this (questioning why not encourage students to build an application completely from scratch) but after a little thought I can see the motivation behind this decision. I think they want students to focus on the more important aspects of the application. However, I can’t help feeling that too much has been done already, in particular I think the image and image collection classes shouldn’t just be given to students as a whole, but I’ll let that slide because my main concerns are with how the existing code base was written.

WAT.

Starting with the main form (because that’s the first thing I saw), straight away I see something a little… odd:

Comic sans though. Really?You’re supposed to be teaching us about GUI design and you use non-system font in the coursework template? What about core UI design concepts like consistency and design guidelines? Do they mean nothing to you?

Moving on from the non-standard font choice, what else is there?

Panels?It looks like the components in the coloured areas are grouped together into relevant containers, which would be nice. Except, those coloured areas aren’t containers at all. They’re not even coloured rectangles. They’re actually coloured labels with an empty text property. Wat. Seriously. They’re not even aligned properly!

Not only is this a strange choice for adding colour to an application, but also a bad one. What if someone using the high-contrast theme wanted to use the application?

Humorously the text is now even less readable now because the theme set the default colour to white (expecting a dark background).

So what about the code? Well other than using Hungarian notation everywhere and prefixing classes with ‘C’ (personal dislike) and enums with ‘e’ (which I have never seen before) the codebase isn’t all that bad. However, there are a number of inefficiencies which I would normally overlook except that this project will set the standard to which students will tend to write their code. For example:

public CPSImage()
{
strFileName = "empty";
lstCategories = new List<eCategory>();
bmpImage = null;
lstKeywords = new List<string>(); //list of keywords associated with the image
strComment = "empty";
rftOrientation = RotateFlipType.RotateNoneFlipNone;
}
public CPSImage(string strFileLoc)
{
strFileName = strFileLoc;
lstCategories = new List<eCategory>();
lstKeywords = new List<string>(); //list of keywords associated with the image
strComment = "empty";
bmpImage = null;
rftOrientation = RotateFlipType.RotateNoneFlipNone;
}

Considering that one of the core mantras taught to students throughout the course is to minimize duplicating functionality in your code, it seems very odd to have it happen all over the place in this project.

Of course, in order to avoid duplication of code, this should really be written as:

public CPSImage(string strFileLoc)
{
strFileName = strFileLoc;
lstCategories = new List<eCategory>();
lstKeywords = new List<string>(); //list of keywords associated with the image
strComment = "empty";
bmpImage = null;
rftOrientation = RotateFlipType.RotateNoneFlipNone;
}
public CPSImage() : this("empty")
{
}

And even then I protest the default definition of any string to “empty” (why not use an empty string?).

Although it has never been suggested at any point that one should improve the template to improve it, I will certainly be doing exactly that. However, if this was actually expected of us, it was never made clear and I highly doubt anyone else will bother.

Keyframe Animation In XNA

Just thought I’d share this. Someone else might find this useful.

Yesterday I had a need to animate an alpha value over time. This was to animate title text in and out when a level loads in my current XNA project for Windows Phone 7 (ooh, exciting!). My first implementation was truly horrific but after a little thought I crafted a nifty little keyframe animation class to make things easier. (There may be a better way to do this but I have yet to see it).

To use the class, just set a load of keyframes when you initialize an Animation object, call Start() and call Update() with the current game time and a reference to the value you want to animate.

Check it out, clone it or whatever on gist.github.com.

Imagine Cup 2011

Yesterday, I competed with my team-mate, Edd Slipszenko at the Microsoft Imagine Cup UK final (hosted at Microsoft’s UK headquarters in Reading). The day itself was a lot of fun and I got to meet and talk to a lot of cool people as well as play some Kinect, Portal 2 and Halo: ODST.

@bennuk dancing to Lady Gaga's "Poker Face" on hard. Over 800,000 points I think

The road to the Imagine Cup final was an interesting one. Edd suggested that we should enter and we eventually wrote the entry for the first round – a proposal for an application to help optimize the use of farm land in the third world. At a loss for a better name, we called it OptiFarm. We also started writing code for the application. We decided to use C# and Windows Presentation Foundation but were lacking experience in these areas. We knew it would be a challenge – but were definitely up for one.

To our surprise, we made it through to round 2: the video presentation round. For this round we had to make a video talking about our project – hopefully with a demo of what we had working so far. At the time we hand almost no actual code to show. All we had were a few classes for storing the data and the start of the internal database. No user interface and no actual results from the application. Despite this, we still managed to create a nice video talking about OptiFarm – although this was rather last minute with the file still uploading to the server when the deadline passed.

With this video we made it through to the UK final ad the real work could begin – except we let it wait and decided not to go with a week to finish. I thought it would be impossible to create even a reasonably good application with 5 days to go. Then Edd convinced me to try anyway.

Within 5 days we created almost 100% of the application we eventually demonstrated to the judges. In that time I think I learned more than I have this year at University – turning from a complete WPF novice into a reasonably competent developer. (Maybe not.)

Either way, we eventually found ourselves at Microsoft’s UK offices to present the fruits of our labours. Although we came 4th, we both learned a lot – both on the way and at the finals. Had we actually worked on it more and prepared our presentation better, I’m sure we could have done better. I’m definitely up for entering again next year.

Congratulations to the winners: Kevin Pfister and Project OVE – I hope you guys have fun in New York (and win the global final of course). I would like to thank Ben Nunney and everybody else who was there for a great experience yesterday.