Friday, January 20, 2006

.Net Generics vs Java Generics

I'm a big fan of Java. It is nice to see the fan base for Java is still far above .Net (and outpacing .Net in growth); see http://www.tiobe.com/tpci.htm

One area I've found .Net outshines Java is the implementation of Generics. Java's Generics exist in source-code only. The Java compiler "Erases" the generic information after the compiler determines that everything is correct. This approach outshines C++ templates, but it creates a lot of other issues. See the Java Generics FAQ which lists pages of special rules and edge cases caused by Erasers. Java Generics is more complex than Java the language!

.Net Generics on the other hand are implemented at runtime. So the Generic type information is not lost and is available through reflection. When the .Net CLR encounters the usage of a Generic type for the first time, it instantiates a non-Generic type based on the type parameters. The Generic type is never executed, it is just used by the CLR to create concrete instances. So Array<string> and Array<float> are two seperate classes at runtime. Java would have just used Array. So .Net memory grows a little more (but not like the bloat of templates in C++), which is a great trade off since it avoids the problems and complexities of Erasures.

Thursday, January 12, 2006

Stop running that startup junk.


A friend asked me how to stop some of those annoying programs that always startup when he starts windows. The best solution I've found is a freeware tool Autoruns from Sysinternals (http://www.sysinternals.com/Utilities/Autoruns.html). Autoruns is a powertool that gives you easy access to everything that is executed at startup. Autoruns allows you to simply uncheck the programs that you don't want to run.

Sysinternals has a number of great tools for performing other tasks. For example, Regmon and Filemon are handy to see what is really going on when installing a program. They are also handy for debugging programs.

Sunday, January 08, 2006

From Ant to Ruby - 122 lines of fun

Last month a friend of mine had a disk failure. Fortunately most of his files are still in good shape. Right now, he is going through the difficult process of trying to recover what files he can. This task is extra difficult since Windows XP encrypts everything under the 'My Documents' folder so that other accounts and OS cant read them. If you are not doing regular backups, you are just asking for trouble.

For almost a year now, I've used a simple Ant script to backup my files. I use a very simple method of copying everything to a separate drive using Ant. The backup also has a few extras that require special steps. For example, backing up my subversion repository requires calling the subversion svnadmin hotcopy command. I've been happy with this process until I wanted to automate backing up data I have stored on the internet. For example, my bookmarks and address book are in yahoo. So I had to manually export them from yahoo to a file, then run my backup script. I looked at using Ant's 'Post' task to automate the web stuff, but I was really unhappy that it wasn't very nice code. Also it was hard to verify that everything worked correctly. If yahoo ever changed a page, the backup might stop getting my data and Ant wouldn't tell me.

So I decided to convert the backup to one of my favorite languages Ruby!

My first task was just a straight conversion of my Ant script to Ruby. The original Ant script was 122 lines of code. When I finished the Ruby version, it came to exactly 122 lines of code! Very funny! This completely surprised me. I had thought Ruby would take more lines of code than Ant. In Ruby I had to write a lengthy backup function (40 lines), and add a few convenience functions. However, when I finished the initial conversion they came out to exactly the same number of lines.

Right now I'm adding more advanced features to my script. Which I will blog about later.