Tuesday, December 30, 2008

ASP.NET MVC or Web Forms?

Nick Berardi has just written a great post ASP.NET MVC vs. ASP.NET Web Forms that compares the pros and cons of using Web Forms or MVC when developing a web application with ASP.NET. The part that I like most about this blog post is the worksheet scoring system that he's created to provide an objective way of choosing between the two.

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 

 

Sunday, December 14, 2008

Oxite

Oxite is a "simple blog engine written using ASP.NET MVC."

At the time of writing this I am hosting this blog using Grafitti CMS. If I was about to start this blog I would select Oxite because:

  1. It uses ASP.NET MVC which I'm familiar with and have done some work on.
  2. It's open source so I can change it easily to suit my needs.

The pain points in moving to Oxite would be:

  1. Converting the blog content and comments to Oxite, data store and format.
  2. Writing link redirection to preserve page rank and avoid broken links.

Friday, December 12, 2008

Silverlight Toolkit December 2008

I've just upgraded the Silverlight Toolkit libraries that I'm using to the December 2008 version.

When reocmpilling my Online Calculators project I discovered that the DynamicSeries type had disappeared but it wasn't listed in the changes section so I had to hunt around for it. I compiled the Toolkit's source and then searched all the files for DynamicSeries and found it left in one of the comments and it appears to have been replaced by the DataPointSeries class.

Replacing the DynamicSeries references with DataPointSeries references got the project to compile and it appears to run correctly.

There has, however been a performance degredation in the auto-updating of the charts in the Mortgage Calculator so I haven't deployed this yet. I'll try and take a look at what's happening and try and optimize my code and see if I can get it back to the current speed before deploying the new libraries.

Wednesday, December 10, 2008

Finding an embedded resource name

I was trying to load an embedded resource into a Silverlight DLL using this code:
 
            System.Reflection.Assembly asm = Assembly.GetExecutingAssembly();
            System.IO.Stream xmlStream = asm.GetManifestResourceStream("Namespace.Filename.xml");
            XDocument xDoc = XDocument.Load(xmlStream);
 
However, the xmlStream was null and hence an exception. I had mistyped the "Namespace.Filename.xml" part of the code but couldn't see what part I'd mistyped. To fix this I changed the code to this:
 
            System.Reflection.Assembly asm = Assembly.GetExecutingAssembly();
            System.IO.Stream xmlStream = asm.GetManifestResourceStream("Namespace.Filename.xml");
            string[] names = asm.GetManifestResourceNames();
            XDocument xDoc = XDocument.Load(xmlStream);
 
and put a break point on the last line and inspected the names array to find the correct name. It was late at night and I was tired so a copy/paste finally resolved to the correct name.

Monday, December 1, 2008

Silverlight Finally

I've finally had a chance to do a bit of work on coming up to speed with Silverlight and thought I'd share my findings and get some feedback.

I've created a Calculator site with a couple (so far) of pages written in Silverlight:
Mortgage Calculator
Temperature Converter

I've been trying to compare Silverlight to its alternatives of Javascript and Flex/Flash. A difficult comparison because I've never used Flex/Flash and my Javascript isn't that great.

Findings from my point of view and my skill set:

Advantages of Silverlight

  1. Language is C# so zero learning curve on that part.
  2. Tools (VS2008 and Blend) are very good - Intellisense made the learning curve less steep for the Silverlight library, architecture and controls.
  3. Web resources good - I hit plenty of small problems (like hosting this on Server 2003) but after a bit of searching found answers to all problems.
  4. Speed - those 2 pages are fairly responsive for what is going on behind them but it's possible that Javascript/Flex could execute at same or better speed. Anybody care to comment on that?

Disadvantages of Silverlight

  1. So far I've only been able to get those pages to work in IE and Chrome and can't get them to work in Firefox.
  2. Opera is not supported yet.
  3. Not everyone will want to install the Silverlight plugin to view those pages.