Luke Hoban Senior Program Manager Microsoft Session Code: DTL310.

Slides:



Advertisements
Similar presentations
 Anders Hejlsberg Technical Fellow Microsoft Corporation TL16.
Advertisements

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Shyam Pather Development Manager Microsoft Session Code: DTL402.
Ken Casada Developer Evangelist Microsoft Switzerland
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Visual Studio 2010 and.NET Framework 4 Training Workshop.
What’s New in C# 4.0? Pavel Yosifovich SELA Group
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Gurinder CTO. Lisa Feigenbaum Microsoft Program Manager Visual Studio Languages
demo video demo Dynamic Languages Simple and succinctImplicitly typedMeta-programmingNo compilation Static Languages RobustPerformantIntelligent.
Louis de Klerk Consultant Inobits Consulting DTL308.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Dynamic Languages & The.Net Framework Shay Friedman ActionBase
Alex Turner C# Compiler PM Session Code: DEV402 On the Dynamic menu today… The Dynamic Language Runtime How does it relate to the CLR? Dynamic in C#
 Jim Hugunin Partner Architect Microsoft Corporation TL10.
Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); object calc.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Tony Whitter Principal, Whitter Technology WMB401 Author Jeff Neafsey Mobility Architect Microsoft.

Lisa Feigenbaum Microsoft Program Manager Session Code: DEV314.
Siddharth Bhatia Senior Program Manager Microsoft Session Code: DTL301.
Ahmed Salijee Developer Advisor
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Scott Hanselman Principal Program Manager Microsoft DTL303.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Thavash Govender Senior BI Consultant iSolve Business Solutions BIN307.
Donald Farmer Microsoft Corporation BIN308.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
Jonathan Aneja Program Manager Microsoft Corporation Session Code: DTL336 Anders Hejlsberg Technical Fellow Microsoft Corporation.
 Boris Jabes Program Manager Lead Microsoft Corporation TL13.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Arend-Jan Speksnijder Solutions Architect Microsoft Dynamics Lighthouse team Dynamics AX2009 Technical Overview and Demo (DYN301)
Tim Rains Group Product Manager Microsoft Session Code: SIA101.
Warren Stevens-Baytopp Director YoungBlood Consultants Session Code BIN303.

OFC308 Hilton Giesenow Development Manager - 3fifteen Host –
Luke Hoban Senior Program Manager Microsoft Session Code: DTL319.
© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel 1 בס " ד.
Scott Morrison Program Manager Microsoft Corporation Session Code: WUX308.
Visual Studio 2010 and.NET Framework 4 Training Workshop.
How We Do Language Design at Microsoft (C#, Visual Basic, F#)
6/13/2018 1:23 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
6/23/2018 8:42 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
6/26/2018 9:02 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Upgrading Your C# Programming Skills to Be a More Effective Developer
9/11/2018 5:53 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
C# in the Big World Mads Torgersen Program Manager
Tech·Ed North America /14/2018 7:13 PM
Visual Studio 2010 and .NET Framework 4 Training Workshop
How We Do Language Design at Microsoft (C#, Visual Basic, F#)
Sysinternals Tutorials
Tech·Ed North America /18/2018 5:14 PM
11/22/2018 8:05 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Jason Zander Unplugged
12/5/2018 3:24 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Tech·Ed North America /17/2019 1:47 AM
2/16/2019 8:43 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Building Silverlight Apps with RIA Services
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Windows 8 Security Internals
Hack-proofing your Clients using Windows 7 Security!
Шитманов Дархан Қаражанұлы Тарих пәнінің
Lap Around the Windows Azure Platform
Presentation transcript:

Luke Hoban Senior Program Manager Microsoft Session Code: DTL310

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

Trends Declarative ConcurrentDynamic

Declarative Programming What How ImperativeDeclarative

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

Concurrency

Co-Evolution

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

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

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…

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

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

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)

Dynamically Typed Objects Luke Hoban Senior Program Manager Microsoft

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(); }

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

Implementing IDynamic Luke Hoban Senior Program Manager Microsoft

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

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");

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

Luke Hoban Senior Program Manager Microsoft

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

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

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

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

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

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

Compiler As a Service Luke Hoban Senior Program Manager Microsoft

International Content & Community Resources for IT Professionals Resources for Developers 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:

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

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

© 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