C# 4.0

I was in Anders Helsberg the Future of C# presentation (actually, in the overflow room).

C# 3.0 most important feature was Expression<Func>.

C# 4.0 most important feature is IDynamicObject.

I think the scenarios enabled by Expression<Func> are far more interesting than the ones enabled by IDynamicObject.

Expression<Func> enabled LinQ to databases and a large number of cool tricks. IDynamicObject enables easy interop with dynamic languages and reflection. I don't see myself using a lot of interop with ruby/phyton, but I will certainly use it for javascript/reflection.

DynamicObject also provides the ability to intercept method calls so a call like "customer.find_by_customer_id(1)' can be translated to the proper expression, as a DynamicObject implementation can intercept the call and do whatever it wants, like "missing method" in ruby.

Support for co/contra variance is something that should have been in C# 3.0, so it's not big news, and the fact that it does not work with value types is disappointing (if you expect an IEnumerable<object> you can pass an IEnumerable<string> but not an IEnumerable<int>).

Optional and named parameters is a cute feature that simplifies some scenarios, but it's also not a killer feature.

The new C# compiler looks interesting, but the fact that he needed to show that at the end of the presentation was a sign of the weakness of the rest of the stuff. It was necessary to show something cool that was not included in C# 4.0 but will be in the future, to excite the audience. In any case, the new compiler looks like a killer feature and could enable some Boo-like extensions to C# that could change the game.

No Comments