Refactoring hell

Arrgggh! I am stuck in refactoring hell with the data access layer code generator addin for visual studio I wrote.

Isn’t it funny how sometimes you think “I can make this so much better if I just change that…” and you end up in a world of pain :-/

Maybe listening to some smashing pumpkins will make it better…

Life on the bleeding edge…

It’s never easy thats for sure. I made the fateful decision the other day to upgrade my Mono installation. Why you say? Well I was seduced by the new language features, partial types, etc so I took the plunge and checked out the latest version from SVN.

Well, that went ok (surprisingly) and I now have Mono-1.1.2.99 installed on my machine. Unfortunately when I started Monodevelop things started to go distinctly astray :-/

I checked the latest version of Monodevelop out from SVN and after quite a few headaches (upgrading to gtk-sharp-2.0, trying to persuade gecko-sharp to compile against gtk-sharp-2.0… the list goes on!) I managed to get it to build, install and run!

Of course as soon as I opened a c# file it crashed… sigh.

Date comparison with Null is super slow!

I was recently performance testing a logging component I’d written which simply logs entries to text file when I stumbled on a performance bottle neck I’d never come accross before.

I wrote the following simple test:

System.Diagnostics.Debug.WriteLine(“Starting 10000 logs entries at: ” + DateTime.Now.TimeOfDay.ToString());


for(int i = 0; i < 10000; i++)

Logger.Instance.CreateLogEntry(“New entry number ” + i.ToString());

System.Diagnostics.Debug.WriteLine(“Finished writing entries at: ” + DateTime.Now.TimeOfDay.ToString());

This managed 10,000 writes in 0.5 secs. I then added the following line into the CreateLogEntry method:

if (_logDate.Date != DateTime.Now.Date)

I was using this check to see if the date had rolled over to the next day (This component is used by a windows serivce that runs continuously and creates a new log file each day). When I re-ran my test imagine my horror to see that the 10,000 writes was now taking 5 mins and 19 secs!

For a moment I wondered how date comparisons in .NET could possible be so slow, and it was then that I realised I was never initialising _logDate, so each time the CreateLogEntry method was called I was doing a comparison between DateTime.Now.Date and null. After fixing my mistake I was back to doing 10,000 writes in 0.53 secs… much better!

It did teach me an important leason though. Comparison with null is very expensive and should be avoided at all costs if performance is a priority.

Mono is cool!

I recently built myself a new computer, and this thing is a beast. AMD Athlon64 3400+, 1Gb RAM, a bit over half a terabyte of SATA disk, Nvidia FX5900 with 128Mb VRAM, and other assorted goodies 😉

I am runnng 64 bit Gentoo on this machine, and it is blisteringly quick!

So over the last week or so I finally got some time to get Mono running. It was a bit of a challenge as the 64bit port of mono is fairly fresh (read need to get from CVS). I have however managed to get it build and installed and was able to test it by building a simple little hello world type console app.

The cool thing about using the 1.1.1 version from CVS is that it includes gcms, which is the new mono compiler for generics. So, I have had a quick play with generics with mono and I like!

So if you have a .NET runtime, what is the next thing your going to want? Yep, an IDE. I checked out a plugin for eclipse (which I use for my C/C++ coding) however all it really gave you was syntax formating. Coming from VS.NET I am a little spoiled and I really wanted tab completion. So I looked into monodevelop. Getting monodevelop to compile took a few goes getting the dependancies etc satisfied, however a day or so ago I managed to get it running and bliss! I now have code completion for 64 bit .NET (with generics support) all on my linux machine.

I am a happy camper.

DataSets – the fog clears

Well, I’ve been using datasets since I started using .NET about 3.5 years ago, but in the past few days I’ve learnt a few new things that I thought I’d share with you.

Datasets are not stored internally as xml. I guess I had always assumed that they were, probably for a couple of reasons. One; I think someone told me this early in my .NET experience; and Two, datasets handle xml so well it almost seems like a logical conclusion. Suffice it to say, I was wrong, and you can find out all the details here.

Another point of dataset enlightenment I had is this:

Databinder.Eval is bad! Apparently ( and I must admit I haven’t written any tests to prove this, although it does make sense ) using Databinder.Eval is about 20% slower than using explicit casting. This is because Databinder.Eval uses reflection to figure out what the type of the object in the container is that you are trying to display. So instead of doing something like this:

<%# Databinder.Eval(Container.DataItem, “MyItem”) %>

you should do something like this:

<%# ((DataRowView)Container.DataItem)[“MyItem”] %>

however if you do this, you will also need to add this line

<%@ Import Namespace=”System.Data”%>

to the top of your html page , otherwise you will get the following error at runtime:

Compiler Error Message: CS0246: The type or namespace name ‘DataRowView’ could not be found (are you missing a using directive or an assembly reference?

You can find out more about this here.

First Post to my new blog!

Well, I thought it was about time I got my act togeather and got a blog going. I know I am a bit late jumping on this particular bandwagon, however I have just recently started reading a lot of other peoples blogs (particularly .NET related stuff ) and am find the experience very rewarding. I especially like the ability to syndicate content from blogs using RSS and have it all on my desktop in one nice easy to find location.

Anyways, this will be a place for me to write my random thoughts, and post any .NET tidbits I come across or dream up.

I guess a link back to my website is probably in order as well 😉