The Future of C# (4.0)

C# 1.0 Managed code
C# 2.0 Generics
C# 3.0 Language integrated query
C# 4.0 Dynamic programming
C# vNext Compiler as a service
Trends
- Declarative
- Dynamic
- Concurrent
- Dynamic
- Concurrent
New paradigm is multi paradigm. C# is very object oriented, but since C# 3.0 it is also a functional programming. These trends are influencing the future of C# coming in C# 4.0
Dynamic language runtime build up out of expression trees, dynamic dispatch, call site caching. The DLR will have binders for different technologies.
Dynamic typed Objects
- Statically typed to be dynamic
- Dynamic conversion
- Dynamic method invocation
example:
dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);
*Anders Hejlsberg shows a pretty impressive demo in which he copies a JavaScript fragment into a .cs file and runs it by changing explicit typed variables with the new dynamic keyword.
How does this work? IDynamicTypedObject is the new interface to implement. Implementing the object GetMember(..) and void SetMember(..) of these interface definition is enough to create dynamic objects.
*You can think of this as native support for DuckTyping. Perhaps this will even bring Arjen over to the bright side.
Optional and named parameters
*A restriction is that a named parameter must come last.
Improved COM interoperability
- Automatic object -> dynamic mapping
- Optional and named parameters
- Indexed property
- Optional "ref" modifier
- Interop type embedding ("No PIA") no primary interop assembly
Co- and contra-variance
objects[0] = "Hello"; // OK
objects[1] = new Button(); // Exception!
- .NET arrays are co-variant, but not safely co-variant
- Until now generics have been invariant
C# 4.0 now supports safe co-and contra invariance.
IEnumerable<out T>
out = Covariant output positions only.
IComparer<in T>
in = Contra-variant input positions only.
Variance in C# 4.0
- Supported for interfaces and delegate types
- "Statically checked definition-site variance"
- Value types are always invariant
- Ref and out parameters need invariant type
*Some of the interfaces in the .NET Framework are using this new feature.
Beyond C# 4.0
- Meda-data programming
- Support for domain specific languages
*We need a compiler that isn't just a black box.
Example:
CSharpEvaluator ev = new CSharpEvaluator ();
ev.Add("System");
ev.Eval("int Sqr(int x) { return x * x; }");
*Anders Hejlsberg shows a couple of very, very impressive demo's. Incredible!
See http://code.msdn.microsoft.com/csharpfuture for more information.