PREPARATION

* Wear VB t-shirt. Note: doesn’t go with brown trousers/shoes.

* Install an x64 machine with Win8, VS2010 (full version, not express) and VS11

*Have the project VB10toVB11improvements (initial) on disk

* Start demo with VS11 open

DevConnections 2012, Vegas - VBLucian Wischik

* Deep breath. Smile, and look over the audience.

* START WITH ENERGY! Encourage applause at appropriate moments.

* Hi! I'm Lucian Wischik. I'm a program manager on the languages design team at Microsoft.

* More specifically, I’m the VB language guy. I drive VB language design, and own its spec. Been doing it since 2009.

* You’re here because you use the language and want to know what’s new, how it will help you in your day-to-day programming.

Heap of improvements

* Well, do I have a treat for you! This coming release is packed with improvements.

* Since VS2010 we’ve opened up new platforms for VB.

* We fixed bugs and added features that users asked for, and spent a lot of effort on perf.

* We improved bits of the IDE, to make that day-to-day coding easier.

* Those three areas are how I’ll structure this talk. Platforms, Requested features, Faster Simpler IDE.

DEMO: Win8 and Async

* I want to dive straight into platforms.

* And the biggest new platform, of course, is Windows 8.

* …

Platforms

* Win8 was just one of the story.

* In the past we’ve had problems with VB not being supported on the newer platforms.

* That was our fault. VB was just too hard to port. Entirely due to Microsoft.VisualBasic.dll.

* Huge DLL, a load of legacy functions, and helper functions, and touches huge swathes of the .NET framework.

* So when a platform came along that didn’t include the whole framework – like XNA, or Phone, or MicroFramework, well, they couldn’t port Microsoft.VisualBasic.dll, and so they couldn’t support VB.

* In VS2010 SP1 we added a compiler feature, VBCore.

* Removes the reference to that DLL. Instead it embeds the core bits needed into your assembly. That makes it easy to support VB on all new platforms.

User feedback

* So apart from this platform support, what else is in VB11?

* I looked through our bug database from the past two years, and every checkin we made, and put together this pie chart.

* It’s an approximation. Sometimes a bug takes two hours; sometimes it takes two weeks. I tried to estimate the person-hours we put into each thing.

* Biggest chunk was Async and Win8, which I’ve mentioned.

* But where did the rest come from?

WATSON.

* Whenever VS crashes, and you decide to send feedback to Microsoft, it goes through an automated system that figures out which DLL was at fault, and automatically creates a bug, and assigns it to the right team.

* We treat crash bugs the most seriously of all.

* Actually, there was a bug in VS2010 which meant that its Watson reports were largely useless. We fixed in in SP1, and so the Watson reports came from since then.

* I think we fixed about 41 crash-bugs. from Watson and other sources like Connect.

PERF-WATSON

* This is an add-in for VS2010 that you can chose to install.

* Whenever VS hangs for longer than 200ms (which is what our User Experience experts say is the threshold of noticeability), then it kicks in. It gathers all relevant information about what was happening at that exact moment. And sends it to us.

* Once again, it figures out which team was at fault, and automatically assigns a bug to the right team.

* I think we made about 34 separate fixes to improve perf.

* In most cases that meant picking a more efficient algorithm, one that runs faster or uses less memory.

* Sometimes it meant using async, to push work onto a background thread so it doesn’t interrupt the UI or doesn’t interfere with your typing speed.

CONNECT

* Connect is the best place for people to file language bugs.

* We’re pretty conservative when it comes to changing the language. That’s because every change might be a breaking change. Most breaking changes we have to decline, even though they look nice on paper.

* Sometimes we make changes just to clean up the language, like if feature X is allowed in one context then it should be allowed in another.

* Or if the compiler deviates from the spec, sometimes we change the compiler, and sometimes we change the spec. The spec is in your C:\program files\microsoft visual studio 11\vb\specification\1033

* In all cases, we prioritize language bugs that have evidence of user-impact. That means, if we know that real users are really suffering from a bug, then we’ll do something about it.

* If it’s just a theoretical bug, then our conservatism comes into play.

* I think we made about 35 fixes to language bugs, some from us, some from Connect.

* Actually, a bunch of these were really mini-feature-requests.

USER-VOICE

* UserVoice is the best place to make feature requests.

* A website where you comment and vote on top ideas, or submit your own.

* What we like is that it’s prioritized for us.

* As a division we’re very scenario-driven. For language features, we’ll only add a feature if we understand in concrete code terms what code you’ll write with it, and how it’s better than the alternative. And we’ll only do it if we believe that scenario is common enough to be worth it.

* (Of course, once we buy the scenario, then we’ll work at making the language feature as clean as possible, hopefully borrowing a mathematically pure design from MSR, and we’ll make it as general as makes sense.)

DEMO: New Language Features

* Well that’s how we decided what new language features to add.

* I’ve already mentioned Async. Let’s spend more time to learn about the others!

* …

Co-Evolution

* One of the biggest user sentiments, I think, was reassurance on the role of VB.

* I think you’ll agree – with the work we did to open up VB to new platforms, and these new language features, that we’ve pretty much delivered.

* VB11 is one of the strongest releases of VB.

DEMO: Faster Simpler IDE

* One of the big requests after VS2010 was to improve perf. We’ve done a lot of that, but I can’t really demo it. Please install VS11 and try them for yourselves.

* I want to look at places where we’ve made the day-to-day life of coding in VB more pleasurable.

* …

Tinkering

* That’s it! Here’s a picture of my motorcycle, a Honda CX500 from 1980. I got custom license plates for it that say “I’m a VB”.

* Please download VS11 beta. Try out the new language features. Explore the platforms.

Links

* Here are links on where to get started.

* You only need to write down the first one. These slides and source code will be available from that site in a day or two.

* Thank you!

DEMO 1: WINRT AND ASYNC

1. File>New>Project>VB>WinMetro

* Browse around the templates

2. File>Open>PaddleGameMetroVB

* Actually, that’s a bit dry. I’ve been playing around with writing a Metro game recently. Let’s use that instead.

3. Run it.

* Well, that was fun!

* Look, the focus of my talk isn’t on how to write Win8 apps.

* I’m really just putting it here to show VB for Win8 is here.

* Actually, there is one thing I wanted to show you about Win8 programming.

4. OnNavigated: MessageBox

* What’s the most popular debugging tool in the world? – printf and MessageBox!

* Well, in Win8, nothing ever blocks. No APIs block. Printf and MessageBox don’t exist as such.

* Instead, they’re all “asynchronous” like Silverlight. That means you sign up for continuations that get run once the thing has finished.

Dim op1 = New Windows.UI.Popups.MessageDialog("hello").ShowAsync()

op1.Completed =

Sub()

Dispatcher.InvokeAsync(

Core.CoreDispatcherPriority.Normal,

Sub()

Dim op2 = New Windows.UI.Popups.MessageDialog("world").ShowAsync()

End Sub, Me, Nothing)

End Sub

* Gulp.

5. Await keyword

* Actually, we don't need any of that.

Await New Windows.UI.Popups.MessageDialog("hello").ShowAsync()

Await New Windows.UI.Popups.MessageDialog("world").ShowAsync()

* Heh. I guess it should have been "goodbye world"

* What the message is, is that Win8 has a new programming model, and VB (and C#) have stepped up to make it easy.

6. Look through to LoadBitmap

* Asynchrony is ubiquitous in Win8 programming. You’ll be using Await a heck of a lot.

DEMO2.1: CALLERINFO

1. Ctrl+Q, Option Strict, turn it on

2. File>New>Project>ConsoleApplicationVB

3. Add a simple logging function:

Sub Log(mesg As String)

Console.WriteLine(mesg)

End Sub

Log("Initializing")

4. For our logging, want file and line numbers

Sub Log(mesg As String,

file As String,

line As Integer)

Console.WriteLine("{0}:{1} - {2}", IO.Path.GetFileName(file), line, mesg)

End Sub

People asked us to add macros like C++:

Log("Initializing", __FILE__, __LINE__)

Other people know that this isn't needed. You can use stack-walking.

If you ship PDBs with your application, and aren't in partial trust,

and can take a few 100ms perf hit, then stack-walkings fine.

5. We went better.

Sub Log(mesg As String,

<CallerFilePath> Optional file As String = "",

<CallerLineNumber> Optional line As Integer = 0)

6. Even better with INotifyPropertyChanged

* Bear with me while I set up, same old boilerplate

Class C

Implements INotifyPropertyChanged

Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

Private _p As Integer

Public Property p As Integer

Get

Return _p

End Get

Set(value As Integer)

Setter(_p, value, "p")

End Set

End Property

Sub Setter(Of T)(ByRefoldval As T, newval As T,

member As String)

oldval = newval

RaiseEventPropertyChanged(Me, New PropertyChangedEventArgs(member))

End Sub

End Class

7. And let's use the same CallerInfo feature

Setter(_p, value)

<CallerMemberName> Optional member As String = "")

8. Test harness

Dim x As New C

x.p = 15

9. Well, let's do it properly

Sub Setter(Of T As IComparable(Of T))(ByRefoldval As T, newval As T,

<CallerMemberName> Optional member As String = "")

If oldval Is Nothing AndAlsonewvalIs Nothing Then Return

If oldvalIsNot Nothing AndAlsooldval.CompareTo(newval) = 0 Then Return

(I guess we could also provide a nullable version if necessary, but I won't bother)

DEMO 2.2: ITERATORS

10. Delete everything

11. Start with IEnumerable

For Each fn In GetPics()

Console.WriteLine(fn)

Next

12. Array literals

Return {"a.jpg", "b.jpg", "c.jpg"}

13. Construct a list and return it

Dim x As New List(Of String) From {

"a.jpg",

"b.jpg"}

x.Add("c.jpg")

Return x

14. In this case, there's something already built in

Dim path1 = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)

Return IO.Directory.EnumerateFiles(path1, "*.jpg")

15. But actually there are some pictures I want to get in the shared pictures folder.

How to do that? Well, I could

Dim path1 = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)

For Each fn In IO.Directory.EnumerateFiles(path1, "*.jpg")

Yield fn

Next

Dim path2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures)

For Each fn In IO.Directory.EnumerateFiles(path2, "*.jpg")

Yield fn

Next

16. Well, let's do something useful with that

Dim xml =

<html

<body

<%= From fn In GetPics()

Select <a href=<%= fn %>imgsrc=<%= fn %> width="200" height="200"/</a>

%>

</body>

</html>

My.Computer.FileSystem.WriteAllText("a.html", xml.ToString(), False)

System.Diagnostics.Process.Start("a.html")

17. Imagine I wanted to do some processing in there, something that can't be done in LINQ

Maybe load the image to find its width and height.

I'm going to stick an iterator lambda right in there. C# can't do this!

<%= Iterator Function()

For Each fn In GetPics()

Yield <a href=<%= fn %>imgsrc=<%= fn %> width="200" height="200"/</a>

Next

End Function()

%>

18. One other thing that C# can't do...

Try

...

Catch ex As IO.DirectoryNotFoundException

End Try

19. While we're here, let's look at Call Hierarchy, new for VB11.

(RightClickViewCallHierarchy)

Run magnifier as well.

DEMO 2.3: NAMESPACE GLOBAL

20. Delete everything

21. Want to declare a class in System namespace

* Common sort of need for code-generators.

Namespace System

Class C

End Class

End Namespace

22. But... it's not really in the system namespace!

It's inside the project root namespace. Everything is.

Dim x As New System.C

Dim y As New Global.ConsoleApplication3.System.C

23. Go to the Project Properties to see.

24. We could remove this. But that's a heavy hammer. It takes EVERYTHING

in our project out of the root namespace. We don't really want that.

New feature: Namespace Global

Namespace Global.System

Dim y As New Global.System.C

DEMO3.1: CODESPIT/PRETTYLIST

1. VB2010. Double-click on Button1 handler

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

2. Taskbar > Show Windows Stacked

Open project in VS11. Double-click on the Button2 handler

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

No more "ByVal". No more fully-qualified typenames.

3. No longer insert useless parentheses

Throe New Exception

4. Better attributes in parameters

Sub Log(msg As String,

<CallerMemberName> |

5. Better spit for Subs

Dim f = Sub |

DEMO 3.2: ANYCPU32

6. Make-believe

* Now here we're going to have to play a bit of make-believe because I haven't set up

my laptop right. And 10pm the night before your conference at a hotel is the wrong

time to reinstall your operating system...

VB10: set a breakpoint on Button1_Click

F5 to run it. Click the button. It hits it.

Imagine your app is target:AnyCPU. It has to be because you want it to work on ARM

tablets. But your development machine is x64 of course. And you try to type in code here.

And you can't, because it says "ENC isn't supported on x64".

7. VS11: Open Project Properties > Compile

It targets AnyCPU. But also "Prefer 32-bit".

8. Set breakpoint on Button2_Click. F5 to run it. Click the button. It hits it.

Console.WriteLine("enc")

and F10.

DEMO 3.3: LAMBDAS, ERRORS

9. VB10: go to Class1.vb and uncomment all of it.

See the masses of errors on the first lambda about overload resolution.

File>Save

10. VB11: go to the same class.

Get a clear error report!

11. Ctrl+Shift+B to see maximum number of errors. 102 for IDE.

But if we did it at the command-line, then it will show all of them.

DEMO3.4: LANGUAGE STUFF

1. Lift For Each

* In a WPF app, add three textboxes

For Each c In {TextBox1, TextBox2, TextBox3}

Dispatcher.BeginInvoke(Sub() c.Text = “Finished”)

Next

* Observe: in VS2010, didn’t do what you expect. Like the squiggly says.

2. Return array literals

Option Strict On

Function f() As String()

If DateTime.Now.Hour < 12 Then

Return {}

Else

Return {"vodka", "whiskey", "martini"}

End If

End Function Dispatcher.BeginInvoke(

3. Optional parameter overloads

Sub PrintDOB(ByVal name As String)

Sub PrintDOB(ByVal name As String, Optional ByVal calendar As Integer = 0)

4. Overload resolution

Sub h(Of T)(ByVal x As T)

Sub h(Of T)(ByVal x As IEnumerable(Of T))

Dim x As IEnumerable(Of Integer) = {1, 2, 3}

h(x)