Geeks With Blogs


Bill Evjen's Blog Code, Life and Community

Presentation by Anders Hejlsberg.

It is 10 years later since they started C#

C# 1.0 was about introducing the general concept of managed code. C# 2.0 was about finishing C# 1.0 but didn't have time to do.

C# 3.0 is really about radical new thinking in the language - LINQ. They learned a lot about functional programming through this exercise. Today is about C# 4.0.

Some of the trends that have shaped their thinking on C# 4.0.

  • Declarative
  • Dynamic - resurgence of dynamic programming languages
  • Concurrent - multi-core processing

Declarative programming. When we write programs today about what we want done and how we want it done. JIT compilers have a big issue figuring out what the developer actually wants to do so it works through everything step by step.

C# is about moving to a more declarative style of programming.

Dynamic vs Static programming languages

  • Dynamic languages
    • Simple and succinct
    • Implicitly typed
    • Meta-programming
    • No compilation
  • Static languages
    • Robust
    • Performant
    • Intelligent tools
    • Better scaling

Concurrency - Moore's Law has delivered what it said - every 18 months of increased density. CPU has fallen flat and hasn't kept up with this since heat has become an issue. The thing that is interesting about the multi-core revolution - separating a logical set of work into multiple sets of work. This doesn't mean that you just make everything work in parallel. There are some important consequences that you are going to have to be aware of.

Co-Evolution - there are no differences between the users of VB and C#. We are going to co-evolve the languages going forward. This means that if we introduce the features in one - then we will work hard to make that feature available in the other.

C# 4.0 - the broad theme for this release is Dynamic Programming. Talking to things that have no static .NET classes backing them. This could be JavaScript, REST services, things that don't feel integrated into the language. Things that don't have a schema.

C# 4.0

  • Dynamically typed objects
  • optional and named parameters
  • improved COM interoperability
  • Co- and Contra- variance for interface and delegate types

.NET Dynamic Programming

  • Dynamic Language Runtime - something we have been building. The DLR extends the CLR fabric to allow dynamic languages to run on the top of .NET. Optimizations on poll-side caching.
  • On top of the DLR, we are building implementations on top of IronPython, IronRuby, and others
  • We will have an Object Binder and a JavaScript Binder, Python Binder, Ruby Binder, and a COM Binder - the DLR will provide a unified view of working with all of these environments

Dynamically Typed Objects

Calculator calc = GetCalculator();
int sum = calc.Add(10, 20);

What if you didn't know what was being returned by the GetCalculator() method?

C# 4.0:

dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);

  • Statically typed to be dynamic
  • Provides dynamic conversion
  • Dynamic method invocation

Anders asked if he is crazy as he promoted against this in the past. The reality is that there are many things out there that are dynamic in nature, that have no schema, that have dynamic entry points in the cloud. There is lots of dynamism in the world. We are trying to more natively integrate this into the language.

You can declare things whose compile time type is dynamic

dynamic x = 1;
dynamic y = "Hello";
dynamic z = new List<int> {1, 2, 3};

IDynamicObject - new interface in .NET 4.0

Possible to write your own dynamic objects - you can create your own interpretations of dealing with dynamic objects.

Optional and Named Parameters - It is now possible to specify default values in method declaration.

public StreamReader OpenTextFile(string path, Encoding encoding = null);

This improves COM interoperability. Instead of ref missing, ref missing, ref missing ... etc ... you can just pass in what you need - doc.SaveAs("Test.docx");

Improved COM Interoperability

  • Automatic object --> dynamic mapping
  • Optional and named parameters
  • Indexed properties
  • Optional "ref" modifier
  • Interop type embedding ("No PIA")

Last new feature is co- and contra- variance

string[] string = GetStromgArray();

void Process(object[] objects) {
   objects[0] = "Hello"; // OK
   objects[1] = new Button(); // Exception

C# 4.0 supports safe co- and contra- variance Until now, C# generics have been invariant.

Variance in C# 4.0

  • Supported for interface and delegate types
  • "Statically checked definition-site variance"
  • Value types are always invariant
    • IEnumerable<int> is not IEnumerable<object>
    • Similar to existing rules for arrays
  • refs and out parameters need invariant type

These changes will have no effect on existing code

Preview of beyond C# 4.0 -------

Stuff in the lab that MSFT will ship as soon as they can.

"Compiler as a Service"
Currently: Source File --> Compiler --> .NET Assembly

This is written in C++ (as C# didn't exist yet). You have no options of interacting with the compiler. MSFT wants to open up the compiler and interact with it in a better way.

Possibilities - meta programming, etc. Microsoft.CSharp will be an API that you can use in your API. This is the C# compiler written in C#.

Technorati Tags: ,,,
Posted on Wednesday, October 29, 2008 6:06 PM | Back to top

Comments on this post: SESSION NOTES: The Future of C#

# re: SESSION NOTES: The Future of C#
Requesting Gravatar...
Thank you very much for these session notes; the information on what will be in C# 4.0 is a bit sparse and segmented. I'm a bit disappointed that non-nullable reference types aren't on the list, but I guess we cannot have everything.
Left by Luke Breuer on Oct 30, 2008 4:44 AM

# re: SESSION NOTES: The Future of C#
Requesting Gravatar...
C# compiler written in C# is kind of cool, but at this point my biggest blocks in productivity are frustrating API decisions by Microsoft that they've acknowledged but not changed. These affect more than just one language, and should probably be more important for this reason.
Left by John "Z-Bo" Zabroski on Oct 30, 2008 2:43 PM

# re: SESSION NOTES: The Future of C#
Requesting Gravatar...
Hey, that was interesting,

looks like C# will be having a bright future...

Keep up the good work
Left by software developer on Oct 13, 2009 10:23 PM

Your comment:
 (will show your gravatar)

Copyright © Bill Evjen | Powered by: