No PDC would be true to form if it didn’t leave you really really baffled and breathtaken. Anders talks tend to do that to you. This year certainly was not exception to that rule. Neither Anders talk nor PDC for breathtakenness (is that even a word?)! I just saw Anders demo cool stuff from the upcoming C# 4.0 and C# 5.0! Even though I’d already seen some of the stuff from Anders earlier talk on the languages I was still blown away! All of what I wrote in that post still applies and here are a few added points:
The über trend of all trends in programming languages today is the break down of language barriers like static/dynamic or declarative/imperative. We will se language makers infuse languages with elements of both. In C# this means that even though it is a statically typed OO language it has already and will continue to gain elements of both functional languages and dynamic languages.
Languages will move to more declarative approaches. Evidence of this is LINQ in C# but this move will continue.
VB and C# is promised to continue it’s co-evolution without the promise that it will be an exactly equal feature set in both languages. C# will not, for instance, get xml literals.
Behind the guise of the dynamic codeword is some really cool magic. dynamic in C# is a new static type! ;~) Presenters here at PDC couldn’t say that enough and couldn’t stop giggling when they did! If you call out to COM for instance (say you are doing office development) and get an object type in return. Today you have to cast it to something useful that you already know it is. Well now all of those APIs will return the static type dynamic which will infer a dynamic conversion to the type you declare. This means you don’t have to cast – it’s inferred from context in the run time! What’s cool abut this is that you can assign anything to a dynamic declaration, say an anonymous type! dynamic is a way to talk to anything that isn’t a .NET type in a type safe (though run time deferred) and efficient way. The declaration is compile time dynamic but run time static. Also method resolution is deferred to run time since you can use dynamic as parameters to methods and the run time will select the correct overload to call in the run time.
The Dynamic Language Runtime, the DLR, is to be viewed as an extension of the CLR enabling static languages and dynamic to coexist and communicate. Here I am sliding over to the talk by Jim Hugunin – Deep Dive: Dynamic Languages in Microsoft .NET. That’s OK though because the two talks were related and Anders actually stole a whole lot of Jim’s thunder during his presentation. Jim is the man behind the Iron Python project. This is done by means of expression trees, dynamic dispatch and call site caching. The DLR team have been able to isolate the features common to most languages and been able to create a way to make binders from any language to any other language over the DLR. Sort of. There are binders to .NET, Ruby, what ever. and if you want to create your own binder, either that you feel you can make a better one or you want to bind to a new language, you can. And it’s not hard to do. There was a very cool new interface called IDynamicObject that when implemented realizes all of this. It is hard to for me to describe this since I’ve only seen it once myself. But I urge you to go look at these two sessions from PDC if you are interested in more (Anders future of C# and Jims Dynamic Languages in .NET)!
In C# 4.0 we also get optional and named parameters built in. This will make it more easy and a lot more powerful to for instance create instances of objects without having a bunch of constructor overloads that only vary the parameters. Now parameters can be optional by supplying a default value. You may also call any parameter by the way of a colon “:” notation – named arguments. Non optional parameters have to be part of you call but you can order your parameters any way you like.
And there will be support for contra and co-variance. This was impossible earlier:
IEnumerable<string> strings;
DoSomethingWitObjects(strings); // This would fail!
public void DoSomethingWitObjects(IEnumerable<object> objects) { […] }
Now instead you will mark the declaration in your method with out… or was it in… I forgot. The one was covariant (out) the other was contravariant (in). They are the opposite and solve different previous problems. Hmmm… I’ll post again on that later. (There is one attempt at an explanation here: The Future of C# (4.0). A bunch of the classic interfaces have been modified with these new flags: Like IEnumerable<out T> and IComparer<in T>.
The site for the news is here: C# Future and the document with all the new features is here: New Features in C# 4.0. <- THIS is the perfect resource for all of this!
And into the future of the future…
In C# 5.0 we will see the opening up of the compiler with an API allowing you to call in to create pieces of code at run-time! This is something of the coolest and most powerful C# has gotten added with that I know of. It will take some time still before we see this addition but it will be here soon. I can’t wait! Anders showed you can make strings into runable code – a really powerful scripting engine that is – in the run time and execute them at will. This dynamic code will appear as needed and disappear when used to end. This is so awesome!
Cheers,
M.
Technorati Tags:
PDC08,
Microsoft,
C#
posted @ Tuesday, October 28, 2008 1:07 PM