Thursday, December 25, 2008

Mix 09 TenK Challenge

I've written a Silverlight control to enter into the Mix09 TenK Challenge. This is my entry: BMI Calculator and here is the main gallery page with all the entries.

At the time of writing this (9am on Christmas day) I'd finished the project and checked the file sizes. 21,438 bytes - about double what I'm aloud. I'm now going to remove all comments, spaces etc. and refactor all variables down to a couple of letters each.

During the exercise of reducing the code size I did a number of things:

  1. I refactored my code. I went through everything I had written and found fragments of unused or unnecessary code and removed them. I also discovered all sorts of size inefficiencies in what I'd done and during this process reduced the code size, made it more maintainable and in the process faster. This came as a bit of a surprise because I didn't realize how much of an improvement refactoring would make to my code and as an exercise has opened my eyes to doing this more often.
  2. I used VS2008's refactor feature to rename variables and function names to single and two letter names.
  3. In the XAML files I considered each attribute and if I was explicitly declaring the default value then I removed it. This had probably happened when I changed from the default to a specific value and then back again.
  4. In all files I removed newlines, replaced tabs with spaces and then replaced double spaces with single spaces. The last operation (replacing double spaces with single spaces) needed to be run four to five times to remove all the redundant spaces.

In the end I managed to reduce the code to 9,617 bytes. I also learned a ton about Silverlight in the process, especially how little code is really needed in the App.xaml and App.xaml.cs files.

There was another feature that I wanted to put into this calculator which I'd left out because I suspected that it wouldn't have fitted in. With hindsight that appears to have been the correct decision as I don't think the remaining few hundred bytes would have been sufficient space.

Links to posts about the Mix 09 TenK Challenge:

Tamir Khason - How to write a program without XAML
Bill Reiss - Thoughts on the MIX 10K challenge
Jobi Joy - Tips used to limit code size 

 

1 comment:

  1. I'm amazed that there are already 55 entries in this competition. I thought that there would be something like 20 at the outside. There are still about 2 weeks before it closes so there may be as many as 100. Also, most of the entries are of high quality in my opinion.

    ReplyDelete