Home Contact

Timmy Kokke

…just sorting my bubbles…

News



Timmy Kokke's Blog

↑ Grab this Headline Animator

Timmy Kokke at Blogged

Twitter












Tag Cloud


Archives

Post Categories

Image Galleries

Silverlight

Syndication:

Shrinking code for the Mix09 10k challenge

Before I share the details of my entry for the challenge 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!


Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: