SESSION NOTES: The Future of C#

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();
Process(strings);

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: ,,,

Google Loses - Authors Win!

 

I blogged years ago and voiced my disappointment of Google taking books, scanning them, databasing the contents of the books, and then making these books available to end users in "chucks". I am a computer book author and have written 18 books (two more on the way) and I wrote in my old blog post about why I didn't care for this move and how it really hurt me as an author. Back then, I wrote about the issue:

"The problem is (at least for publishers and authors) is that let's say there is someone trying to figure out how to use the new XmlDataSource control and they enter that word into Google Print and get directed to my book to a specific page where this is discussed. The reader on Google can then scroll through the couple of pages reading up on this control and then they are done. Granted, they didn't scroll through the entire book, but they are able to get what they need from a publication without needing to purchase this publication.

I do like people using my books to learn and to help them do their jobs, but at the same time - it takes me 4-5 months to write a book ... it is a ALOT of work and I would hope that people would purchase a title I have written instead of pulling what they need from it from Google for free. You don't get paid much as an author, but it sure is nice to get a bit of a reward for all the hard work."

John Wiley stepped up to the plate and joined in on the lawsuit against Google for copyright infringement. Google was arguing that they should be allowed to do this for the end user as they are only showing excepts and not the entire book. This move, if it had gone through, is quite detrimental to authors and in turn to end users. In the end, Google lost the case and will have to pay $125 million USD for the past infringements. Side note to my editor: "How much of this do I get?" ;)

In any case, a deal has been established to create a registry that will still allow Google to proceed with their plans, but charge end users for the "chucks" of books that they view. Some argue that this will change how people will consume books and a move to more digital consumption of books. It defiantly is an interesting notion.

Related Posts:

Business Week: Google Settles with Authors
Blog Post from Oct 20 2005: John Wiley & Pearson Sue Google

«October»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678