Shrinking code for the Mix09 10k challenge

Before I share the details of my entry for I’ve got some tips for you to help you shrink the size your code:

  • Xaml isn’t needed, it only takes up a lot of space. Read this article on using Silverlight without Xaml.
  • Returns, tabs and spaces are bytes and increase the size of your file. Almost all may be removed. Every space next to punctuations may be removed, even next to keywords.
  • Define arrays like this: int[]c=new{1,2,3,4,5}; Without any spaces. Note, the “int” that usualy goes between “new” and “{“ can be ommited.
  • Put all classes in 1 file. This makes sure you use ever usings once.
  • When you’re done with you program, rename every class, variable, field, method and namespace to 1 or 2 characters. Use the 1 characters for the fields and methods that are used the most of course.
  • When declaring variables. Use the “var” keyword where you can, unless you’re declaring something shorter of your own.
  • Use lambdas when handling events. For examle: C.MouseMove += (s, e) => {Update(e.GetPosition(C));};
  • Create derived classes for the ones that you use a lot. I used Canvas a lot, so I did: public class C: Canvas{} and used “C” instead of “Canvas”.
  • Create methods to shorten access to normal methods. I my case I had to add stuff to a Canvas a lot, so I shortened it. For example: aCanvas.Children.Add(aTextBlock); could become: AddChild(aCanvas,aTextBlock); With a method like void AddChild(Panel P, UIElement U) { P.Children.Add(U); } Everything will be written as one character in the end of course. So the method call would look likeA(b,c); instead of b.Children.Add(c);
  • Forget everything you’ve learned and hardcode everything. No fancy constructions are needed.
  • If you are in doubt if some code is called, place a breakpoint and check. Every line less will help create a smaller file.
  • Remove all formating. ALL formating. This is the last step, because your code will be almost unreadable after this.

Good luck in the contest!

This article is part of the GWB Archives. Original Author: Timmy Kokke

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.