Joseph Guadagno

Rants, Raves and other stuff about ASP.NET development.

PDC 2008 Experience: Day 1: Session = "The Future of C#"

Co-Evolution of languages: When one feature or capability is added to one language, the feature or ability to have that feature will be placed in the other language.

This is a bit incomplete.  I could not type as fast as slides move.  I will update it when I get the slides.

C# 4.0: Dynamic Programming.

C# 4.0 Language Enhancements

  • Dynamically Typed Objects
  • Optional and Named Parameters
  • Improved COM Interoperability
  • Co and Contra variance

Dynamically Typed Objects

Dynamic Language Runtime

  • Expression Trees
  • Dynamic Dispatch
  • Call Site caching

C# and VB.NET will have support for dynamic language.  The Dynamic Runtime will provide the ability to talk to IronPython, Ruby, JavaScript and others.

   1: dynamic calc = new Calculator();
   2: int result = calc.Add(10, 20);

Andres took some Silverlight JavaScript methods and with search and replace made it into C# using the "dynamic" language runtime.

IDynamic Object

TODO: FIX Code; I could not type it fast enough.

   1: using System.Dynamic;
   2:  
   3: public class Bag: DynamicObject
   4: {
   5:     Dictionary<string, object> items = new Dictionary,string, object>();
   6:     public override object GetMember(System.Scripting.ActionsGetMemberAction action, it)
   7:     {
   8:  
   9:     }
  10:  
  11: }
  12:  
  13: class Program
  14: {
  15:     static void Main(string[] args)
  16:     {    
  17:         dynamic x= new Bag();
  18:         x.ID = 12345;
  19:         x.Name = "Lawn Mower";
  20:         x.Price = 795;
  21:         
  22:     }
  23:     private static void WriteBag(dynamic x) {
  24:         Console.WriteLine ();
  25:     }
  26: }

Optional and Named Parameters

Optional Parameters

   1: public StreamReader OpenTextFile(
   2:     string path;
   3:     Encoding = null;
   4:     bool detectEncoding = true;
   5:     int bufferSize = 1024)

Named Arguments

   1: OpenTextFile("foo.txt", Encoding.UTF8, buffersize: 4096);

 

Improved COM Interoperability

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

Interop calls do not need to be cast.

TODO: GET Excel Interop sample.

Co and Contra variance

   1: string[] strings = GetStringArray();
   2: Process(strings);
   3:  
   4: ...
   5:  
   6: void Process (string[] input) {...}

can be done using the new C# 4.0 support for safe co- and contra-variance

   1: // Covariant
   2: public interface IEnumerable<out T>
   3: {
   4:     IEnumerable<T> GetEnumerator();
   5: }
   6:  
   7: // Can be treated a less derived
   8: public interface IEnumerable<out t>
   9: {
  10:     T Current get;}
  11:     bool MoveNext();
  12: }

Variance in C#

  • Support for interface and delegate types
  • "statically checked definitions"
  • TODO: Add missing elements

Coming Soon to C#

A new compiler, compiler as a service... Source files -> compiler -> .NET Assembly

This will allow applications to hook into the compiling service for testing, checks, and more.

Posted: Oct 27 2008, 03:51 PM by jguadagno | with 5 comment(s)
Filed under: , , ,

Comments

Reflective Perspective - Chris Alcock » The Morning Brew #210 said:

Pingback from  Reflective Perspective - Chris Alcock  &raquo; The Morning Brew #210

# October 28, 2008 4:42 AM

w.meints said:

Its quite hard to read, but I am excited to see this article in its final form. Screw the dynamic stuff, I want optional and named parameters!!

# October 28, 2008 1:54 PM

Maurice Reeves said:

I was excited until I saw "Optional Parameters".  That's such a kludge!  I get that it will improve interop between scripting languages and C# but it's such a horribly abused feature in VB.Net now.  BLEH.

# October 28, 2008 4:21 PM

No Time To Read PDC Blogs :( « Tales from a Trading Desk said:

Pingback from  No Time To Read PDC Blogs :( &laquo; Tales from a Trading Desk

# October 28, 2008 7:18 PM

qwe said:

AGree, screw dynamics. If you wanted them you had them in x languages for over 15 years.

Where are the mix-ins?

Where is the new VM?

Where is the new modern and even approachable to Java's JIT?

# October 31, 2008 6:01 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)