Presentation is loading. Please wait.

Presentation is loading. Please wait.

Luke Hoban Senior Program Manager Microsoft Session Code: DTL310.

Similar presentations


Presentation on theme: "Luke Hoban Senior Program Manager Microsoft Session Code: DTL310."— Presentation transcript:

1

2 Luke Hoban Senior Program Manager Microsoft Session Code: DTL310

3 The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query

4 Trends Declarative ConcurrentDynamic

5 Declarative Programming What How ImperativeDeclarative

6 Dynamic vs. Static Dynamic Languages Simple and succinctImplicitly typedMeta-programmingNo compilation Static Languages RobustPerformantIntelligent toolsBetter scaling

7 Concurrency

8 Co-Evolution

9 The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming

10 Dynamically Typed Objects Optional and Named Parameters Improved COM Interoperability Co- and Contra-variance C# 4.0 Language Innovations

11 Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder.NET Dynamic Programming Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPythonIronPythonIronRubyIronRubyC#C#VB.NETVB.NETOthers…Others…

12 Dynamically Typed Objects Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); ScriptObject calc = GetCalculator(); object res = calc.Invoke("Add", 10, 20); int sum = Convert.ToInt32(res); ScriptObject calc = GetCalculator(); object res = calc.Invoke("Add", 10, 20); int sum = Convert.ToInt32(res); dynamic calc = GetCalculator(); int sum = calc.Add(10, 20); dynamic calc = GetCalculator(); int sum = calc.Add(10, 20); Statically typed to be dynamic Dynamic method invocation Dynamic conversion

13 Dynamically Typed Objects dynamic x = 1; dynamic y = "Hello"; dynamic z = new List { 1, 2, 3 }; dynamic x = 1; dynamic y = "Hello"; dynamic z = new List { 1, 2, 3 }; Compile-time type dynamic Run-time type System.Int32 When operand(s) are dynamic… Member selection deferred to run-time At run-time, actual type(s) substituted for dynamic Static result type of operation is dynamic

14 public static class Math { public static decimal Abs(decimal value); public static double Abs(double value); public static float Abs(float value); public static int Abs(int value); public static long Abs(long value); public static sbyte Abs(sbyte value); public static short Abs(short value);... } public static class Math { public static decimal Abs(decimal value); public static double Abs(double value); public static float Abs(float value); public static int Abs(int value); public static long Abs(long value); public static sbyte Abs(sbyte value); public static short Abs(short value);... } double x = 1.75; double y = Math.Abs(x); double x = 1.75; double y = Math.Abs(x); dynamic x = 1.75; dynamic y = Math.Abs(x); dynamic x = 1.75; dynamic y = Math.Abs(x); Dynamically Typed Objects Method chosen at compile-time: double Abs(double x) Method chosen at run-time: double Abs(double x) dynamic x = 2; dynamic y = Math.Abs(x); dynamic x = 2; dynamic y = Math.Abs(x); Method chosen at run-time: int Abs(int x)

15 Dynamically Typed Objects Luke Hoban Senior Program Manager Microsoft

16 IDynamicObject public abstract class DynamicObject : IDynamicObject { public virtual object GetMember(GetMemberBinder info); public virtual object SetMember(SetMemberBinder info, object value); public virtual object DeleteMember(DeleteMemberBinder info); public virtual object UnaryOperation(UnaryOperationBinder info); public virtual object BinaryOperation(BinaryOperationBinder info, object arg); public virtual object Convert(ConvertBinder info); public virtual object Invoke(InvokeBinder info, object[] args); public virtual object InvokeMember(InvokeMemberBinder info, object[] args); public virtual object CreateInstance(CreateInstanceBinder info, object[] args); public virtual object GetIndex(GetIndexBinder info, object[] indices); public virtual object SetIndex(SetIndexBinder info, object[] indices, object value); public virtual object DeleteIndex(DeleteIndexBinder info, object[] indices); public MetaObject IDynamicObject.GetMetaObject(); } public abstract class DynamicObject : IDynamicObject { public virtual object GetMember(GetMemberBinder info); public virtual object SetMember(SetMemberBinder info, object value); public virtual object DeleteMember(DeleteMemberBinder info); public virtual object UnaryOperation(UnaryOperationBinder info); public virtual object BinaryOperation(BinaryOperationBinder info, object arg); public virtual object Convert(ConvertBinder info); public virtual object Invoke(InvokeBinder info, object[] args); public virtual object InvokeMember(InvokeMemberBinder info, object[] args); public virtual object CreateInstance(CreateInstanceBinder info, object[] args); public virtual object GetIndex(GetIndexBinder info, object[] indices); public virtual object SetIndex(SetIndexBinder info, object[] indices, object value); public virtual object DeleteIndex(DeleteIndexBinder info, object[] indices); public MetaObject IDynamicObject.GetMetaObject(); }

17 Optional and Named Parameters public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding); public StreamReader OpenTextFile( string path, Encoding encoding); public StreamReader OpenTextFile( string path); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding); public StreamReader OpenTextFile( string path, Encoding encoding); public StreamReader OpenTextFile( string path); Primary method Secondary overloads Call primary with default values

18 Implementing IDynamic Luke Hoban Senior Program Manager Microsoft

19 Optional and Named Parameters public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding = null, bool detectEncoding = true, int bufferSize = 1024); public StreamReader OpenTextFile( string path, Encoding encoding = null, bool detectEncoding = true, int bufferSize = 1024); Optional parameters OpenTextFile("foo.txt", Encoding.UTF8); OpenTextFile("foo.txt", Encoding.UTF8, bufferSize: 4096); Named argument OpenTextFile( bufferSize: 4096, path: "foo.txt", detectEncoding: false); OpenTextFile( bufferSize: 4096, path: "foo.txt", detectEncoding: false); Named arguments must be last Non-optional must be specified Arguments evaluated in order written Named arguments can appear in any order

20 Improved COM Interoperability object fileName = "Test.docx"; object missing = System.Reflection.Missing.Value; doc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); object fileName = "Test.docx"; object missing = System.Reflection.Missing.Value; doc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); doc.SaveAs("Test.docx"); doc.SaveAs("Test.docx");

21 Automatic object  dynamic mapping Optional and named parameters Indexed properties Optional “ref” modifier Interop type embedding (“No PIA”) Improved COM Interoperability

22 Luke Hoban Senior Program Manager Microsoft

23 Co- and Contra-variance void Process(object[] objects) { … } string[] strings = GetStringArray(); Process(strings); string[] strings = GetStringArray(); Process(strings); void Process(object[] objects) { objects[0] = "Hello"; // Ok objects[1] = new Button(); // Exception! } void Process(object[] objects) { objects[0] = "Hello"; // Ok objects[1] = new Button(); // Exception! } List strings = GetStringList(); Process(strings); List strings = GetStringList(); Process(strings); void Process(IEnumerable objects) { … }.NET arrays are co-variant …but not safely co-variant Until now, C# generics have been invariant void Process(IEnumerable objects) { // IEnumerable is read-only and // therefore safely co-variant } void Process(IEnumerable objects) { // IEnumerable is read-only and // therefore safely co-variant } C# 4.0 supports safe co- and contra-variance

24 Safe Co- and Contra-variance public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } out = Co-variant Output positions only IEnumerable strings = GetStrings(); IEnumerable objects = strings; IEnumerable strings = GetStrings(); IEnumerable objects = strings; Can be treated as less derived public interface IComparer { int Compare(T x, T y); } public interface IComparer { int Compare(T x, T y); } public interface IComparer { int Compare(T x, T y); } public interface IComparer { int Compare(T x, T y); } IComparer objComp = GetComparer(); IComparer strComp = objComp; IComparer objComp = GetComparer(); IComparer strComp = objComp; in = Contra-variant Input positions only Can be treated as more derived

25 Supported for interface and delegate types “Statically checked definition-site variance” Value types are always invariant IEnumerable is not IEnumerable Similar to existing rules for arrays ref and out parameters need invariant type Variance in C# 4.0

26 Variance in.NET Framework 4.0 System.Collections.Generic.IEnumerable System.Collections.Generic.IEnumerator System.Linq.IQueryable System.Collections.Generic.IComparer System.Collections.Generic.IEqualityComparer System.IComparable System.Collections.Generic.IEnumerable System.Collections.Generic.IEnumerator System.Linq.IQueryable System.Collections.Generic.IComparer System.Collections.Generic.IEqualityComparer System.IComparable Interfaces System.Func System.Action System.Predicate System.Comparison System.EventHandler System.Func System.Action System.Predicate System.Comparison System.EventHandler Delegates

27 The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming

28 Compiler Compiler as a Service Compiler Source code Source File Source code.NET Assembly Class Field public Foo private string X X Meta-programmingRead-Eval-Print Loop Language Object Model DSL Embedding

29 Compiler As a Service Luke Hoban Senior Program Manager Microsoft

30

31 www.microsoft.com/teched International Content & Community http://microsoft.com/technet Resources for IT Professionals http://microsoft.com/msdn Resources for Developers www.microsoft.com/learning Microsoft Certification & Training Resources Resources Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings from Tech-Ed website. These will only be available after the event. Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings from Tech-Ed website. These will only be available after the event. Tech ·Ed Africa 2009 sessions will be made available for download the week after the event from: www.tech-ed.co.zawww.tech-ed.co.za

32 Related Sessions WhenWhatAreaCode Mon 8:00Future Directions for Visual BasicLanguagesDTL308 Mon 9:15The Manycore Shift: Making Parallel Computing Mainstream CLR/BCLDTL206 Mon 17:15The State of Dynamic Languages on the Microsoft.NET Framework LanguagesDTL304 Tue 9:15Introduction to F#LanguagesDTL319 Tue 10:50.NET Languages and Development ToolsLanguagesWTB218 Wed 10:15How LINQ Works: A Deep Dive into the Microsoft Visual Basic and C# Implementations LanguagesDTL401

33 Required Slide Complete a session evaluation and enter to win! 10 pairs of MP3 sunglasses to be won

34 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Required Slide


Download ppt "Luke Hoban Senior Program Manager Microsoft Session Code: DTL310."

Similar presentations


Ads by Google