tirsdag, oktober 31, 2006

Anders Hejlsberg in Copenhagen (IT University)

I just learned from my former professor (Peter Sestoft) that Anders Hejlsberg will host a guest lecture at ITU, Copenhagen on November 10th at 14:00 hours.

As you probably already know, Anders is the man behind C# and this lecture will contain a walkthrough of the new language features of C# 3.0 as well as his reasons for including these language features in this future release of C#.

C# 3.0 will include really cool features like:
- Implicitly typed local variable declaration: (for example var i = 42)
- Extension methods (the possibility to extend existing types with additional methods)
- Lambda expressions (cool SML like syntax for methods: x=> x + 42 )
- Greater type inference
- Object and collection initializers ( shorter syntax for creating instances)
- Anonymous types (like: new{Name = “Runi”, Language=”C sharp”})
- Implicity types arrays
- And the LINQ (declarative type safe access to query relational and hieratical data)

To register for this FREE event, register here:
http://www.microsoft.dk/MSDN/Hejlsberg@ITU

I will surely be there - see you all.

/Runi

fredag, oktober 27, 2006

Sitecore Instructur at last

I have yesterday reached the level of higher existence (or competence) - Sitecore V5 Certified Instructor, Level 2.

I just completed my first instruction in the Sitecore API course. It was actually quite giving and interesting to teach Sitecore on a lower level, surely something I want to do again.

Actually, if everything goes well, my next instruction session will be in Holland sometime late next month.

onsdag, oktober 25, 2006

Dont trust your debugger

I just waisted a couple of hours because of a strange behaviour in the Visual Studio debugger.
Consider the following code:

object
obj = new String('a',1); //"a"
string str = new String('a',1); //"a"
Console.Out.WriteLine(obj == str); //ln1
Console.Out.WriteLine(str == obj); //ln2
Console.Out.WriteLine((string)obj == str);//ln3
Console.Out.WriteLine(str ==(string)obj); //ln4
Console.Out.WriteLine(obj.Equals(str)); //ln5
Console.Out.WriteLine(str.Equals(obj)); //ln6

Now, add breakpoints in Visulal Studio on line 1 to 6 - and make the debugger evaluate the expression before it is printet to the console.


What would you (the debugger) expect the output to be? The Visual Studio Debugger says:
true
true
true
true
true
true


This is however not the case. The actual output is:
false
false
true
true
true
true


There is really nothing strange about the result. The == operator does not just call the Equals method blindly and virtually as one might expect. It is actually an operator that compares references unless overridden.

By default the == operator compares for reference equality. So if == tests for reference equality, this would explain the behavior of the result of ln1 and ln2, but not ln 3 and 4. This is because the == operator has been overridden in the String class to call the Equals method, thus comparing the value of the string rather than its reference. (this explains ln 3 and 4).

The runtime system determines which operator to call based on the runtime type (the type of the reference rather than the type of the instance). In ln 1 and 2 the == operator of the Object class is used, where in ln3 and ln4 the operator as defined in the String class is used.

So much for the == operator. The strange thing however, is that the Visual Studio debugger does not seam to get this. (VS2003). I used a lot of time debugging an expression inside an 'if' statement, which evaluated to false (by the debugger) but the if - statement - body was entered anyway. Grrr – I’m a bit pissed at the debugger.