I saw a really good presentation on the future of C# by Anders Hejlsberg, the lead architect of the team developing the C# programming language. This was a popular talk as he got to present it twice this week.
Anders outlined the history of major advances in C# as this:
- 1.0 – Introduction of Managed Code
- 2.0 – Generics (and everything else we wanted in 1.0 but didn’t have time to do)
- 3.0 – Language Integrated Query
He observed that the trends in Programming Languages today were towards languages that were: Declarative, Dynamic, and Concurrent.
Declarative vs. Imperative
Declarative (vs Imperative) are languages with mutations, variables. The need may be on WHAT we need done but the focus is primarily on HOW we want it done. The JIT compiler can’t really determine the WHAT. The Declarative style allows for better interpretation by the language infrastructure at compile time. Think of it like this:
| Declarative |
Imperative |
| Dynamic |
Static |
| Simple & Succinct |
Robust |
| Implicitly Typed |
Performant |
| Meta-Programming |
Intelligent Tools |
| No Compilation |
Better Scaling |
Both of these types have something to contribute – but we really need a combination. Be as static as possible and dynamic where needed.
Concurrent
What exactly is Concurrency? Lots of people seem to have their own definition. Anders described it in these terms: Multi-cpu systems are a reality. We need to know how to program to use the cores effectively. How do you break a logical unit of work and run it on multiple cores?
C# 4.0
OK – so on to what to expect with C# 4.0:
- Main focus is on Dynamic Programming
- Dynamically Typed Objects
- Optional and Named Parameters
- Improved COM Interop
- Co and Contra Invariance
- Dynamic Language Run-time – (Part of .NET 4.0)
- Expression Trees
- Dynamic Dispatch
- Call Site Caching
Note that VB.NET will also be getting this support.
C# will also be introducing Object Binders. For example: Javascript Binders for Silverlight, COM Binders for Office, others as well (for Ruby and Python).
Dynamic Language Support
Dynamic Languages today require different syntax or very complex syntax if the type is unknown. The new “Dynamic” Keyword changes all this. This is essentially System.Object with a “Dynamic” attribute. Cloud computing increases the need to do this significantly.
When Operands are dynamic, the member selection is deferred to run-time. At run-time, the actual types are substituted for the dynamic placeholder. Method Overloads can also be done with Dynamic instead. Just changes where the replacement occurs.
A new extension method AsDynamic allows static types to be able to invoke dynamic dispatch. So existing types can take advantage of the new functionality.
The functionality provides an Idyllic Interface. You can write your own dynamic objects. Then you buildup your own interpretation of how the dynamic replacement will work at runtime.
Other Features
Optional and Named Parameters are now supported. This has been in VB.NET for a while. Named arguments must always be last in an invocation.
There is improved COM Interoperability. No longer need to specify “System.Reflection.Missing.Value” parameters. This helps geatly with Office calls which have many named and optional parameters. Interop Type Embedding (the reducing of the size of DLLs needed by encapsulating only the functionality being used), provides a much smaller footprint. It also removes the need for casting as well.
Anders also talked a bit about Co- and Contra-variance. However this part went right over my head
I’ll have to follow up on that later.
C# 5.0 and Beyond
Future C# work will focus on the compiler as a service. C# merely becomes a callable object. An example of this is Jascripts EVAL function – only you will be able to do it now directly in C#. Programmers can even define functions within it.