Mix 10K Coding Challenge - Few Tips I have used to limit the code size



While developing for the MIX 10K coding challenge, the major challenge to face is to limit the code in 10K size. So I had to question each and every line of code that would it be possible to write this even with fewer bytes.
 Check out my application at http://2009.visitmix.com/MIXtify/TenKDisplay.aspx?SubmissionID=0044 Make sure to run the application in fullscreen mode.
 Here I am compiling a list of tips and features I used to reduce the code size. 
1.       Automatic Properties - Used this .NET feature to create the Tweet class which represents an RSS feed item from the search result   
public class Tweet {
  public string Guid { get;set; }
  public string Title { get;set; }
  public string Author { get;set;

    … ….

2.       Object Initializers
new Tweet {Title = element.Element("title").Value,
Author = element.Element("author").Value,
Guid = element.Element("guid").Value}};
3.       LINQ to XML - I have used this to read the XML stream from the search result handler.
4.       Collection Initializer - Collection initialize has used along with the LINQ query, which does a huge amount of job with fewer lines.
5.       Use 'Var' - Used to initialize a variable without specifying its type
 The bellow few lines do all the work to grab the RSS feed in to a collection variable which utilizes the features 3,4 and 5 above
XElement elements = XElement.Parse(e.Result);
var items = from element inelements.Descendants("item")
select new Tweet { PrevZ = double.NaN, Title = element.Element("title").Value
 6.       Anonymous functions - This save you some bytes. Bellow line I have used to toggle between the Fullscreen modes when the user clicks on a checkbox named 'chkFullScreen'
chkFullScreen.Click +=delegate{Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen; };
 7.        Remove all Private keywords - Default member accessor is 'Private' so you don’t need to specify that :)
8.       Remove all unused 'Using' statements - Easy ways to check – When you finish coding, removes all the ‘using’ statements and then correct the compile error
Some other editing tricks (This can make the source code un-readable too).
  Reduce the Tab size to zero
  Remove all white spaces
  Make the entire source code into few lines.
  Put all the source code in to a single source file 
  Single character variable names.

I haven’t used much of these editing tricks. The code was just 8.96KB. So I kept the source readable and in 4 separate files.

Comments

Popular posts from this blog

Time Picker User Control

A simple Multiselect ComboBox using expression Blend

A Simple Radial Panel for WPF and SilverLight