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:
- 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.
- I used VS2008's refactor feature to rename variables and function names to single and two letter names.
- 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.
- 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: