Thursday, July 31, 2008

Well, despite my joy in finding a bug it seems that the issue of the overload polymorphism question is moot. Its a choice.

The compiler can choose to ignore the fact that a better parameter match exists and use a lazy evaluation of a method in a derived class. Apparently, this doesn't break the rules of OOP or of polymorphism. It just prevents "brittle base class" syndrome.

Personally, although I can see a certain validity in the arguments of MS gurus like Eric Lippert I still feel as though the wool has been pulled over my eyes somewhat. How I missed such a simple thing as this for the last eight years is a mystery to me. I must be getting old.

Ahh well. I suppose I had better brush up on my VB syntax because despite the fact that the language is verbose and redundant they have a kick-ass compiler that is proven to be better at
loop optimisation and now I discover that it handles an important compiler principle in a logical and intuitive way.

Thursday, July 24, 2008

Still bugs in the C# compiler.

I have been putting together some simple training for VB6 developers who have had little or no experience with C# or object orientation and I found this lovely bug in the compiler.

Speaking with a friend who works for Microsoft he quickly said it wasn't a bug and gave me a line about explicit casting and method selection in the compiler but I think that the example is really simple and is a clear breach of overloading principles.

I have a base class with a virtual method which contains an integer parameter. In a derived class I include both an override for the original method plus an overload for the same method but this time having a float parameter.

The main function calls the derived class and even when the parameter is cast explicitly to int, the int overload is never called.

This is true in the 2005 and 2008 versions.

To prove a point I wrote the exact equivalent functionality in VB.net and it works as expected.

Here's the code.

class Program

{

static void Main(string[] args)

{

DerivedClass dc = new DerivedClass();

dc.AMethod((int)1);

dc.AMethod(1f);

Console.ReadKey();

}

}

class BaseClass

{

public virtual void AMethod(int i)

{

Console.WriteLine("Base class integer parameter!");

}

}

class DerivedClass : BaseClass

{

public override void AMethod(int i)

{

Console.WriteLine("Derived class integer parameter");

}

public void AMethod(float f)

{

Console.WriteLine("Derived class float parameter");

}

}

Sunday, July 13, 2008

Grandad

When I was a boy I had the great fortune to have lived at my grandparents home for a while whilst the family was in-between houses.

The times I liked most was the mornings. I would hear grandma in the kitchen as she made the breakfast, she would often hum or sing a tune as she worked. Grandad would call us down and we’d have scrambled eggs on toast or boiled eggs. Grandma and granddad were a great team.

Being the first grandchild I suppose I got the benefit of his own feeling of grandfatherhood. We spent a lot of time together and he would often ask me “Robert, do you know how to….” Whereupon, because I most often had no idea, he would launch into a demonstration of something or other. It was granddad who held the saddle of the little bicycle, on which he taught me to ride a “two-wheeler”. It was granddad who introduced me to books without pictures, who gave me a passion for literature and reading and who introduced me to authors like Charles Dickens and H. G. Wells. It was granddad who showed me how to use an index so that I could look for information on my own. He gave me many of the starting points in my young life.

The job I do today is with computers, using math and complex graphics or calculations. All of my skills are rooted in his teaching me how to use a slide-rule or what good the sine and cosines are for and the value of precision in engineering.

In short, I have a deep sense that my granddad contributed a great deal to who I am today.

Later in life I continued my relationship with this man but as an adult. Whenever we saw each other, we would talk at great length on many subjects. Once, he came flying with me when I qualified as a pilot and we flew over his house on the Isle of Wight in a little Piper plane.

Recently, I myself became a grandfather and someone asked me if it made me feel old. I replied that I had actually been looking forward to it a great deal and only hoped that I could be as good a grandfather as the one I was lucky enough to have.

William Anderson

14th December 1906 - 13th July 2008


Tuesday, July 08, 2008

Fuel prices getting you down?

In Europe we're paying 1.5 euros per litre or more at the moment so the question of fuel consumption is a big issue.

Last year we bought a new Honda Jazz, it's a small petrol engined car which the dealer told me was more economical than a diesel. I laughed at this but recently we've been playing a game where my wife and I try to get the best mileage as possible. We've been learning to drive economically but the car is used for all those niggly little taxi journeys that one is obliged to do when one has children.
Driving the car "normally" as in "we don't care about fuel consumption" we were getting 7 litres per 100 kilometres or about 40 miles per gallon.

Recently, since we began the fuel consumption game we reduced it to the 5.5 / 100 region but since last weekend we've done an amazing 4.8 litres per 100 kilometers which works out to 58 miles per imperial gallon!

Cool eh?