Lucian Wischik SESSION CODE: DEV401. Advanced Use of the New Microsoft Visual Basic 2010 Language Features Lucian Wischik, VB spec lead.

Slides:



Advertisements
Similar presentations
Ron Jacobs Technical Evangelist Microsoft Corporation SESSION CODE: DEV207.
Advertisements

Jason Tolley Technical Director ROK Technology Pty Ltd SESSION CODE: WEM305.
demo video demo Dynamic Languages Simple and succinctImplicitly typedMeta-programmingNo compilation Static Languages RobustPerformantIntelligent.
Louis de Klerk Consultant Inobits Consulting DTL308.
Joe Kuemerle Lead Developer PreEmptive Solutions - SESSION CODE: DEV306.
Mark Harmsworth – Architecture Nate Bruneau – Engineering Scott Kleven – Program Management Microsoft Corporation SESSION CODE: OSP321.
Sometimes it is the stuff you know that hinders true progress.
Juergen Thomas Principal Program Manager Microsoft Corporation SESSION CODE: DAT314.
The Secrets of Effective Technical Talks: How to Explain Tech without Tucking Them In! Presented by Mark Minasi and Mark Russinovich SESSION CODE: SIA334.
Ashwin Sarin Program Manager Microsoft Corporation SESSION CODE: COS204.
Maciej Pilecki Consultant, SQL Server MVP Project Botticelli Ltd. SESSION CODE: DAT403.
Boris Jabes Senior Program Manager Microsoft Corporation SESSION CODE: DEV319 Scale & Productivity in Visual C
Peter Provost Sr. Program Manager Microsoft Corporation SESSION CODE: DEV403.
Kevin Cox – SQL CAT Microsoft Corporation What are the largest SQL projects in the world? SESSION CODE: DAT305 Srik Raghavan –
END USER TOOLS AND PERFORMANCE MANAGEMENT APPS Excel PerformancePoint Svcs/ProClarity BI PLATFORM SQL Server Reporting Services SQL Server Reporting Services.
Brad Younge Principal Statera, Inc. SESSION CODE: COS304.
Janssen Jones Virtual Machine MVP Indiana University SESSION CODE: VIR403.
Bradley Millington Senior Program Manager Microsoft Corporation SESSION CODE: WEB 306.
Suhail Dutta Program Manager Microsoft Corporation SESSION CODE: DEV402.
Matt winkler program manager microsoft corporation SESSION CODE: ASI303.
Satya SK Jayanty Director & Principal Architect D BI A Solutions Peter Saddow Senior Program Manager Microsoft Corporation -SQL Server SESSION CODE: DAT312.
Thomas Deml Principal Program Manager Web Platform and Tools Microsoft Corporation SESSION CODE: WEB308.
Paul Litwin Programmer Manager Fred Hutchinson Cancer Research Center SESSION CODE: WEB206.
Huseyin YILDIZ Software Design Engineer Microsoft Corporation SESSION CODE: DEV314.
Jeff King Senior Program Manager, Visual Studio Microsoft Corporation SESSION CODE: WEB305.
Lori Dirks Expression Community Manager Microsoft Corporation SESSION CODE: WEB309.
Paul Schaeflein, MCT Manager of Advanced Technologies LaSalle Consulting Partners, Inc. SESSION CODE: OSP309.
Dan Holme Director of Training & Consulting Intelliem SESSION CODE: OSP214.
Chris Mayo Microsoft Corporation SESSION CODE: UNC207.
Bob Beauchemin Developer Skills Partner SQLskills SESSION CODE: DAT402.
Olivier Bloch Technical Evangelist Microsoft Corporation SESSION CODE: WEM308.
Richard Campbell Co-Founder Strangeloop Networks SESSION CODE: WEB315.
Srinath Venkatasubramanian Alliance Manager Sonata Software Limited SESSION CODE: BIP203.
By: Paul D. Sheriff or SESSION CODE: DEV320.
Kate Gregory Gregory Consulting SESSION CODE: DEV316.
SESSION CODE: MGT205 Chris Harris Program Manager Microsoft Corporation.
Reza Chitsaz Senior Program Manager Microsoft Corporation SESSION CODE: DEV302 Building a SharePoint Collaboration Application in Visual Studio 2010.
Andrew Connell, MVP Developer, Instructor & Author Critical Path Training, LLC. SESSION CODE: OSP305.
Introducing Visual Studio 2010: What It Is and Why You Should Care
Pat Altimore Sr. Consultant Microsoft Corporation SESSION CODE: WCL321.
David Ollason Lead Program Manager Microsoft Corporation SESSION CODE: UNC322 The New Communicator “14” Platform.
BIO202 | Building Effective Data Visualizations and Maps with Microsoft SQL Server 2008 Reporting Services BIU08-INT | Using.
Ted Pattison Author / Instructor Critical Path Training SESSION CODE: OSP315.
Martin Woodward Program Manager Microsoft Corporation SESSION CODE: DEV308.
Don Jones Senior Partner and Technologist Concentrated Technology, LLC SESSION CODE: DAT203.
Jesus Rodriguez Chief Architect, Tellago, Inc Microsoft Architect Advisor Microsoft MVP Oracle SOA ACE SESSION CODE: DEV406.
SESSION CODE: COS301. So what do we do?
Mir Rosenberg & Refaat Issa Program Managers Microsoft Corporation SESSION CODE: WSV401.
Jonathan Aneja Program Manager Microsoft Corporation Session Code: DTL336 Anders Hejlsberg Technical Fellow Microsoft Corporation.
David A. Carley Senior SDE Microsoft Corporation SESSION CODE: DEV318.
By: Paul D. Sheriff or SESSION CODE: WCL206.
Brian A. Randell Senior Consultant MCW Technologies SESSION CODE: DEV311.
Christophe Fiessinger & Jan Kalis Senior Technical Product Manager Microsoft Corporation SESSION CODE: OSP209.
Ken Getz Senior Consultant MCW Technologies, LLC SESSION CODE: WCL202.
Tobias Ternstrom Senior Program Manager Lead SQL Server Engine SESSION CODE: DAT404.
Luke Hoban Senior Program Manager Microsoft Corporation SESSION CODE: DEV307.
Andrew Connell, MVP Developer, Instructor & Author Critical Path Training, LLC. SESSION CODE: OSP319.
Stephen Forte Chief Strategy Officer Telerik stephenforte.net SESSION CODE: DEV303 Building Data Driven RESTful Applications.
How We Do Language Design at Microsoft (C#, Visual Basic, F#)
Tech·Ed North America /18/2018 2:05 PM
Tech·Ed  North America /11/ :01 AM SESSION CODE: DEV405
Implementing RESTful Services Using the Microsoft .NET Framework
Team Foundation Server 2010 for Everyone
Authoring for Microsoft Silverlight 4 with Microsoft Expression Blend
Tech Ed North America /1/ :36 AM Required Slide
Microsoft SharePoint Conference 2009 Jon Flanders
Tech Ed North America /12/2019 6:45 AM Required Slide
A Lap Around Internet Explorer 9 For Developers
Lap Around the Windows Azure Platform
Tech Ed North America /6/2019 2:07 PM Required Slide
Presentation transcript:

Lucian Wischik SESSION CODE: DEV401

Advanced Use of the New Microsoft Visual Basic 2010 Language Features Lucian Wischik, VB spec lead

“Headliner language features will be done for both langs… We pursue parity for MS samples and content.” [scottwil]

VB 9: Dim f = GetType(Fred). _ GetConstructor(New Object() {}). _ Invoke(New Object() {}) VB 10: Dim f = GetType(Fred).GetConstructor({}).Invoke({})

VB 9: Dim x As New List(Of String) Dim y As List(Of Object) = x ' List(Of String) cannot be converted to List(Of Object) VB 10: Dim x As New List(Of String) Dim y As List(Of Object) = x ' List(Of String) cannot be converted to List(Of Object) ' Consider using IEnumerable(Of Object) instead Dim y2 As IEnumerable(Of Object) = x ' Works fine!

Demo DEMO The bulk of the talk is a live demo. The following slides are just placeholders, to indicate the content of the demo.

Demo: Nothing (1) [VS2008] Dim x As Boolean? = Nothing If x = Nothing Then Console.WriteLine("is nothing") What does it do? -doesn’t print anything! Why? - Read on!...

Demo: Nothing (2) [VS2010] Dim x As Boolean? = Nothing If x = Nothing Then Console.WriteLine("is nothing") ' Warning: This expression will always evaluate to Nothing ' (due to null-propagation). To check if the value ' is null, consider using "Is Nothing" Well that’s why it didn’t print anything! - What does it mean?

Demo: Nothing (3) Dim y As Integer? = 5 Dim z = y + Nothing Dim z2 = y * Nothing Console.WriteLine(z.HasValue) Console.WriteLine(z2.HasValue) Nothing means “I don’t know what value it has” (like SQL) - so z and z2 are both “I don’t know” also - So this prints “False” and “False” again

Demo: Nothing (4) Dim z? = If(False, 15, Nothing) Console.WriteLine(z.HasValue) Console.WriteLine(z.Value) This is a different “Nothing” issue -The dominant type is “Integer”, not Nullable(Of Integer) -It interprets “Nothing” as 0 -And so prints “True” and “0”

Demo: Nothing (5) Private _AccessLevel As Integer? Public Property AccessLevel() As Integer? Get Return _AccessLevel End Get Set(ByVal value As Integer?) If _AccessLevel Is Nothing OrElse _AccessLevel <> value Then _AccessLevel = value End Set End Property AccessLevel = 5 AccessLevel = Nothing Console.WriteLine(AccessLevel) - This prints “5”. Can you see the bug? Can you see how to fix it?

Demo: Array trick (1) Module Module1 Sub Main() Dim x As New List(Of String) From { "one", "two", "three"} Dim y As FixedList(Of String) = {"one", "two", "three"} End Sub End Module -“x” is using the Collection Initializer feature, new in VB10 -“y” is a trick with Array Literals (new in VB10) and a user-defined conversion...

Demo: Array trick (2) Class FixedList(Of T) Private _list As New List(Of T) Public Sub New(ByVal x As IEnumerable(Of T)) _list.AddRange(x) End Sub Public Shared Widening Operator CType(ByVal x As T()) As FixedList(Of T) Return New FixedList(Of T)(x) End Operator Default Public ReadOnly Property Item(ByVal i As Integer) As T Get Return _list(i) End Get End Property End Class

Demo: Synchronous call Dim web = Net.WebRequest.Create(" Using r = web.GetResponse, s = New IO.StreamReader(r.GetResponseStream) Console.WriteLine(s.ReadToEnd) End Using This is the basic synchronous way to write this code. -How would we make it asynchronous? -With multiline statement lambdas (new in VB10)!...

Demo: Asynchronous call Dim web = Net.WebRequest.Create(" web.BeginGetResponse(Sub(ir) Using _ r = web.EndGetResponse(ir), s = New IO.StreamReader(r.GetResponseStream) Console.WriteLine(s.ReadToEnd) End Using End Sub, Nothing) Use of multiline statement lambdas -Indispensible for asynchronous programming, Task Parallel Library,...

Demo: Multiline Lambdas Dim x = Function() If Rnd() > 0.5 Then Return 1 Else Return 2.5 End If End Function What is the return type of this lambda? -Here it picks “Double” -In general it picks the DOMINANT TYPE of all return arguments -Dominant type is also used during generic type inference, and in If(...) operator -NB. “Nothing” doesn’t influence the choice of dominant type

Demo: Dynamic (1) Module Module1 Sub Main() Dim o As Object = New Bag o.x = 15 o.y = 20 o.z = 35 Console.WriteLine(o.x + o.y + o.z) End Sub End Module This is a simple use of DLR interop

Demo: Dynamic (2) Class Bag Inherits Dynamic.DynamicObject Private _d As New Dictionary(Of String, Integer) Public Overrides Function TrySetMember(ByVal binder As System.Dynamic.SetMemberBinder, ByVal value As Object) As Boolean _d(binder.Name) = CInt(value) Return True End Function Public Overrides Function TryGetMember(ByVal binder As System.Dynamic.GetMemberBinder, ByRef result As Object) As Boolean Return _d.TryGetValue(binder.Name, result) End Function End Class This is the basic Bag class.

Demo: Dynamic (3) Dim s As String = o Console.WriteLine(s) Dim s2 = CTypeDynamic(Of String)(o) Console.WriteLine(s2) Tricky question: how would we make “o” behave a string, so we could print it?... -NB. CTypeDynamic is new in VB10. It includes dynamic and user-defined conversions. -Ctype doesn’t include either

Demo: Dynamic (4) C#: string s = d; -- TryConvert C#: var x = "hello" + d; -- ToString VB: Dim s as String = d -- IConvertible VB: Dim s = CTypeDynamic(d) – TryConvert VB: var x = "hello" & d -- IConvertible, else operator & VB: var x = "hello" + d -- IConvertible, else operator + It’s a bit of a mess. Here are the different ways needed to make something string-like: Public Overrides Function TryConvert(ByVal binder As System.Dynamic.ConvertBinder, ByRef result As Object) As Boolean If binder.Type = GetType(String) Then result = "tryconverted" : Return True Return MyBase.TryConvert(binder, result) End Function Public Overrides Function ToString() As String Return "tostringed" End Function Public Function GetTypeCode() As System.TypeCode Implements System.IConvertible.GetTypeCode Return System.TypeCode.String End Function Public Function ToString1(ByVal provider As System.IFormatProvider) As String Implements System.IConvertible.ToString Return "iconvertibled" End Function

DEV307: F# in Microsoft Visual Studio 2010 (6/10 from 9:45am – 11:00am) DEV315: Microsoft Visual Studio 2010 Tips and Tricks (6/8 from 5:00pm – 6:15pm) DEV316: Modern Programming with C++Ox in Microsoft Visual C (6/8 from 3:15pm – 4:30pm) DEV319: Scale and Productivity for C++ Developers with Microsoft Visual Studio 2010 (6/9 from 8:00am – 9:15am) DEV401: Advanced Use of the new Microsoft Visual Basic 2010 Language Features (6/9 from 9:45am – 11:00am) DEV404: C# in the Big World (6/8 from 1:30pm – 2:45pm) DEV406: Integrating Dynamic Languages into Your Enterprise Applications (6/8 from 8am – 9:15am) DEV407: Maintaining and Modernizing Existing Applications with Microsoft Visual Studio 2010 (6/10 from 8:00am – 9:15am)

DEV03-INT: Meet the C# team (6/9 from 1:30-2:45pm) DEV04-INT: Meet the VB team (6/10 from 3:15 – 4:30pm) DEV09-INT: Microsoft Visual Basic and C# IDE Tips and Tricks (6/7 from 4:30pm -5:45pm) DEV10-INT: Using Dynamic Languages to build Scriptable Applications ((6/9 from 8:00am -9:15am) DEV11 –INT: IronPython Tools (6/10 from 5:00pm – 6:15pm) DEV05-HOL: Introduction to F#

Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31 st You can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year