240 likes | 500 Views
TOOL-816T. Future directions for C# and Visual Basic. Anders Hejlsberg Technical Fellow Microsoft Corporation. Agenda. What’s new in C# 5.0 and VB 11.0? Asynchronous Metro style C#/VB applications Hybrid C#/VB and Javascript applications A look into the future: The Roslyn project.
E N D
TOOL-816T Future directions for C# and Visual Basic Anders Hejlsberg Technical Fellow Microsoft Corporation
Agenda • What’s new in C# 5.0 and VB 11.0? • Asynchronous Metro style C#/VB applications • Hybrid C#/VB and Javascript applications • A look into the future: The Roslyn project
C# and VB evolution C# 5.0 + VB 11.0 Windows Runtime + Asynchrony C# 4.0 + VB 10.0 Dynamic + Language Parity C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 Generics C# 1.0 + VB 7.0 Managed Code
What’s new? C# 5.0 VB 11.0 Windows Runtime support Asynchronous programming Caller info attributes Iterators • Windows Runtime support • Asynchronous programming • Caller info attributes
Asynchronous programming is becoming the norm in modern, connected applications
Asynchronous programming models • Windows Runtime: IAsyncOperation<T> • .NET Framework: Task<T> • Javascript: Promises • All are objects representing “ongoing operations” • All use callbacks to signal completion of operation • Challenge: Callbacks turn your code inside out • Insight: Automatic transformation to callbacks is possible
Asynchronous methods automatically transform normal code into a callback state machine
Asynchronous methods • publicasyncTask<XElement> GetXmlAsync(stringurl) { • varclient = newHttpClient(); • varresponse = awaitclient.GetAsync(url); • vartext = response.Content.ReadAsString(); • returnXElement.Parse(text); • } publicTask<XElement> GetXmlAsync(stringurl) { vartcs= newTaskCompletionSource<XElement>(); var client = newHttpClient(); client.GetAsync(url).ContinueWith(task => { varresponse = task.Result; vartext = response.Content.ReadAsString(); tcs.SetResult(XElement.Parse(text)); }); returntcs.Task; }
demo Metro style asynchrony
Asynchronous methods… • Are marked with new “async” modifier • Must return void or Task<T> • Use “await” operator to cooperatively yield control • Are resumed when awaited operation completes • Can await anything that implements the “awaiter pattern” • Execute in the synchronization context of their caller • Allow composition using regular programming constructs • Feel just like good old synchronous code!
demo C# and Javascript
Caller Info attributes __FILE__ and __LINE__macros in C#?
Caller Info attributes • publicstaticclassTrace • { • publicstaticvoidWriteLine(string message, • [CallerFilePath] string file = "", • [CallerLineNumber] int line = 0, • [CallerMemberName] string member = "") • { • var s = string.Format("{0}:{1} – {2}: {3}", file, line, member, message); • Console.WriteLine(s); • } • } voidInitialize() { Trace.WriteLine("Starting services"); ... } Trace.WriteLine("Starting services", "c:\\sources\\foo.cs", 1123, "Initialize");
C# and VB evolution C# 5.0 + VB 11.0 Windows Runtime + Asynchrony C# 4.0 + VB 10.0 Dynamic + Language Parity C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 Generics C# 1.0 + VB 7.0 Managed Code
The Roslyn project Meta-programming Read-Eval-Print Loop Class public Foo Language Object Model Field DSL Embedding private X string Compiler Compiler SourceFile .NET Assembly Source code Source code Source code Source code
Roslyn APIs Edit and Continue Signature Help Extract Method Find All References Rename Go To Definition Quick Info Navigate To Object Browser Formatter Colorizer Completion List Outlining Language Service Compiler APIs Syntax Tree API Parser Symbol API Symbols Binding and Flow Analysis APIs Binder Emit API IL Emitter Compiler Pipeline Metadata Import
announcing Visual Studio Roslyn CTP
demo Visual Studio Roslyn CTP
Summary • C# and VB deeply support the Windows Runtime • C# and VB make asynchronous programming easy • You can create hybrid C#/VB and Javascript apps • Visual Studio Roslyn CTP will be available soon
For more information RELATED SESSIONS DOCUMENTATION & ARTICLES • [PLAT-203T] Async everywhere: creating responsive APIs & apps • [TOOL-531T] Using the Windows Runtime from C# and Visual Basic • [SAC-804T] Building IIS and ASP.NET apps with the power of async • [TOOL-810T] Async made simple in Windows 8, with C# and Visual Basic • [TOOL-829T] The zen of async: Best practices for best performance • Visual Studio Asynchronous Programmingwww.msdn.com/vstudio/async • What's New for Visual C# inVisual Studio 11 Developer Preview • http://go.microsoft.com/fwlink/?LinkId=228087 • What's New for Visual Basic inVisual Studio 11 Developer Preview • http://go.microsoft.com/fwlink/?LinkId=228088
thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback
© 2011 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.