A small introduction for these posts you can find here.Today the first day of www.devdays.nl. the day started great with a broken Tom-tom and me taking a wrong turn in The Hague. So I missed the keynote.
First session "C# 4.0 / The Future of C#" http://tinyurl.com/qczdjs by Krishnan Subramanian. Krishnan likes to type code while presenting, so it promised to be a fun session. Krishnan starts with a history lesson:
- C# 1.0 first managed Code
- C# 2.0 Generics
- C# 3.0 LINQ
- C# 4.0 Dynamic programming
trends now in C# declarative, dynamic, concurrency
We are programming very declarative, this creates a lot of noise. Finding out what the code does can be hard. A lot of details go into the how instead of the what. Krishnan uses linq to show that linq already has less noise. His non-technical girlfriend can understand a linq query.
Krishnan says that there is room for static and dynamics languages.
When you look at hardware trends,more and more multi processors machines are getting mainstream. C# 4.0 will give more possibilities for parallel programming. Krishnan demo’s this by using a LINQ ray tracer program this program is part of the parallel extensions. To make it parallel he only uses the .asParralel keyword on a LINQ query.
The themes for C# 4.0 are
- Dynamically typed objects
- Optional and Named Parameters
- improved COM interoperability
- Co- and Contra-variance
The current way to use methods with less or more parameters is to use overloads. In C# 4.0 you have named and optional parameters. The optional parameter feature you can use by setting a default value to the parameter in the method declaration. When calling the method you can use named parameters this makes the code more readable.
For COM interop there are improvements:
- Dynamic mapping
- Optional and named parameters
- Indexed properties
- Optional ref modifier
- interop type embedding
To explain Co- variance you can look at an array of strings and putting a button in it. This is co-variant but not safe. When looking at List<String> and Ienumarble<object> these cannot be cast to each other. In C#4.0 you can now use IEnumarable<in T> and IEnumarable<out T>.
In the future it might be possible to use the compiler as a service. Your program should be able to change compile behaviour.Krishnan shows a demo of code that will compile in the C# version that will come out after C# 4.0. In this he uses a CSharpEvaluator class with which he writes a program from strings. Using this he writes a command line c# interpreter. Kewl.