Tuesday, May 4, 2004

Sometimes Different == Broken.. maybe

Sometimes Different == Broken

I suppose I could rationalize this. I should mention that Delphi doesn't automatically box values, which is a potentially expensive operation; both in performance, and the potential backward compatibility problems. You can enable automatic boxing by using the (*$AUTOBOX ON*) compiler directive. Now your first question is going to be, "why not autobox by default?" The issue is backward compatibility. Consider some existing source code that has the following overloaded functions:


function Func(Value: Variant): Boolean; overload;
function Func(Obj: TObject): Boolean; overload;


Func(1); in previous versions of Delphi would call the Variant version of Func. Now if this code is compiled with Delphi 8 for .NET and autoboxing were to be on by default, the TObject version of Func would be called! The semantics of the code has changed. Since autoboxing is off by default, the user is now spared countless hours of frustration in wondering why the compiler is calling the "wrong" version of Func.

Now for the the auto casting to IComparable. This one is admittedly a little less defensible. I'll have to consult with Danny on the potential solutions. This will certainly depend on internal compiler architecture and other performance considerations.

C# has the benefit of not having any large base of existing source code; the semantics of the language could be defined in any way seen fit. Delphi having to maintain a high level of backward compatibility is both its strength and is a minor weakness.