Category Archives: Visual Basic

An embarrassment of riches on VB 10.0 and Oslo

Now that we’re past the PDC, there are a bunch of video resources coming out on VB 10.0 and Oslo. Here’s a roundup of what’s available so far:

The Pearson folks also recorded some vidcasts they call OnMicrosoft. If you go to the previous link, you can see all the videos posted, but the ones of interest to this blog are:

There are other Oslo vidcasts on the site, so check them out as well.

Future Directions for Visual Basic

Yesterday I gave my valedictory address on Visual Basic at the PDC. I think the talk went well and it was a lot of fun, if not a little sad that it’s one of the last times I’ll be giving a talk about Visual Basic. We covered a lot of exciting stuff, some of which should be familiar to readers of the blog. I’ll let people know when the video is up on the Channel9 page for the talk, should be some time today. For those of you who don’t want to sit through the talk it went something like this:

  • First, we talked a bit about the role of Visual Basic at Microsoft as the language that makes Microsoft platforms really accessible to programmers.
  • Then we segued into talking about the increased commitment that the languages groups are making to ensure that Visual Basic and C# coordinate language features so that users of one language aren’t left out in the cold when the other language adds some useful feature. This isn’t to say that we’re going to do things in exactly the same way, or even that the languages will have exactly the same feature set, but that we’re committing to ensuring that the fundamental capabilities in the languages stay in better sync than they have over the previous eight years.
  • Then Lucian did a really wonderful demo of VB 10.0, which is shipping in Visual Studio 2010. He showed (IIRC) the following features that should be familiar to the readers of this blog: array literals, collection initializers, automatic properties, implicit line continuations, statement lambdas, generic variance, and a feature that embeds primary interop assembly types in your assembly so you don’t have to deploy the PIA. I may have missed some, so check out the video when it’s posted!
  • Finally, we talked about some of the trends that we see affecting Visual Basic going forward and talked about some of the work we’re starting to do for post-VS 2010 to move the Visual Basic compiler to managed code and open it up to the world so that you can take advantage of the services that it provides.

If you attended the talk, please evaluate the session! It helps me become a better speaker and helps us give a better PDC. And feel free to stop by the tools lounge today, I’ll be hanging out there most of the day!

Let’s get small…

I just wanted to give a shout out to my fellow Oslo employee Vijaye Raji whose Small BASIC project just launched on the new DevLabs site. It’s a version of BASIC targeted at truly beginning programmers, and I think it’s a great example of how BASIC can be utilized to make things very simple and easy to use. I got the chance to see Small BASIC in action being taught to high schoolers and it was wonderful to see the kids start to make the connection between what they were doing and what they could do. It’s a great project, and I hope it goes far!

Where to Find Me at PDC2008

I didn’t realize I’ve been so silent about the PDC! I’ve been struggling to get off of .Text and on to Subtext for my blogging engine, and so I’ve been avoiding posting because “I’ll wait until I get moved over to the new engine.” Pffffft! Anyway, I’m going to be doing a number of things at the PDC, so if you’re going to be in LA next week, stop by and say hi!

  • I am co-presenting “Future Directions for Visual Basic” with Lucian on Tuesday at 5:15pm in room 406A. Do stop by and let’s chat about where Visual Basic is going! Also, feel free to go to the Channel9 page and add comments about what you’d like to see and if there are questions you’d like addressed. If you’re not going to the PDC, check the page after the talk for video and discussion.
  • I’ll be at the “Ask the Experts” dinner on Wednesday night in Hall G. I’ll be sitting with Visual Basic, although I might wander over to wherever Oslo is at some point.
  • I’ll be trying to attend the various Oslo talks.
  • I’ll be at the Tools and Languages lounge on Wednesday from 2-5pm for sure, and I’ll probably be hanging around there a lot otherwise.

I’ll be trying to keep up with my Twitter feed (my username is paulvick) so feel free to ping me if you are around. And I’ll blog some more after my talk.

Hope to see you all there!

Please welcome Lucian Wischik!

Hi all, I wanted to take a moment to introduce the new specification lead for Visual Basic, Lucian Wischik. Lucian has been getting to know the user community over the past few months, and now you’ll have even more contact with him as he’ll be taking over my responsibilities in terms of owning the language spec! He’s already been an enormous help in ironing out some of the trickier aspects of the Dev10 spec, and I feel very confident that the specification will be in good hands. Here’s a short bio:

Lucian Wischik is the Visual Basic specification lead. Since joining the VB compiler team a year ago he has worked on new features for Visual Studio 2010 relating to type inference, lambdas and generic covariance. In his four years at Microsoft he has also worked on the Robotics SDK and concurrency, and has published several academic papers on the subject. Before coming to Microsoft he took a PhD in concurrency theory at the University of Cambridge and worked as a researcher at Bologna University in Italy. Despite this theoretical slant, he’s most at home when writing practical code. He’s a keen sailor and long-distance swimmer. His blog can be found at http://blogs.msdn.com/lucian.

Please welcome Lucian!

All good things…

As difficult as it is to say, I wanted to let my loyal readers know that after a decade spent working on Visual Basic, I’ve made the decision to change jobs at Microsoft.

It’s somewhat hard for even me to imagine just how long I’ve worked on Visual Basic. I joined the Developer Division (VB’s home) over 11.5 years ago to work on OLE Automation. A year and a half after that, I moved over to the VB team proper to work on the compiler’s code generator just as we started the move to what would become .NET. In some ways it seems like just yesterday, but in many other ways it feels like several lifetimes ago. In the intervening decade, I’ve worked on 4.1 versions of Visual Basic (including our forthcoming version), during which time an amazing amount of stuff has happened to the VB language, the VB community, Visual Studio, and development tools in general. The development world looks very different than it did when I started, and that’s generally been a wonderful thing.

But as the current release started to wind down from a design perspective, I started asking myself whether it was time for a change. And, after thinking about it quite a bit and talking to quite a few people, I decided that it was. As much fun as it has been to work on Visual Basic, I felt the need to be doing something different than what I’ve been doing. And so I made the decision that it was time to move on. Sort of.

You see, although the fact that I’m leaving is a big deal in some ways, it’s not as big a deal as you might expect. Even as I physically move to another team, in many ways I’m not really going anywhere. I’ll be carrying with me a title of “Visual Basic Language Designer Emeritus,” meaning that I will continue to participate in the VB language design process and will continue to work to ensure the VB language specification is kept complete and up to date (although I will no longer have primary authorship responsibilities). I’m also still planning to give the VB talk at the PDC in October and talking about all the exciting things we’ve done for the upcoming release plus some ideas about where things will be going in the more distant future.

As to my next challenge, well, there isn’t a whole lot I can say about that… yet. I’ve got some personal ideas rattling around in my head that I’m going to get some time to spend working on, but my day job is going to be working with guys like Douglas Purdy, Don Box and Chris Anderson on the Oslo product. In particular, I’m going to be helping out with the subject of this talk. Expect to hear more from me about it once we’ve gotten to the PDC.

Even though I’ll be spending a good bit of my time on Oslo, though, I’ll still going to be an active member of the VB community. I’ll still be talking about VB on this blog, opining on the language and it’s future, and, I’m sure, continuing to answer lots of questions. I’ll be continuing to use VB and am really excited where the product is going in this release and the next one (but more about that at the PDC!). Over time, I do expect my place in the VB community will fade somewhat as the new blood on the VB team really starts to come into its own, but for the time being things will continue to go along much as they have been. And, of course, VB will always have a special place in my heart.

This isn’t really goodbye but I did want to take the opportunity to thank all of the people out there who have used VB, who’ve read my blog, and who’ve written me or talked to me about VB. The VB community has been one of the major reasons that I have enjoyed working on VB so much (and for so long!), and every one of you have played a major role in that. There have certainly been controversies, disagreements, and blow ups, but I really think that VB has one of the finest user communities that I’ve ever participated in, and that I will be lucky if I work on products in the future that attract such a passionate, intelligent, and caring group of people. I can’t say how much I appreciate all the great times that everyone has given me over the years!

So, the blog will continue, I’ll still be talking about VB, and soon I’ll have some additional interesting and exciting things from my new job to talk about too. The next ten years should be just as fun as the previous ten have been!

Iterators in Visual Basic

WARNING: This is a speculative post. Caveat emptor.

Actually, in this case I don’t thing the above warning is strong enough. This is a super speculative post, because I believe the chance of it appearing in the next version of the language is not extremely high, not because it’s not a worthy feature but because it’s more than a little work and we’ve got a lot of other very worthy features we’re considering. However, since it’s something that’s valuable and something we keep getting requests for, we have decided to at least generally sketch out what iterators would look like in Visual Basic, with the idea that when the time comes that we have the resources to do them we can jump on it. Consider yourself double warned.

To start with, an iterator is just a structure that returns a sequence of values. Basically, when the IEnumerable(Of T) interface method GetEnumerator() returns an instance of the interface IEnumerator(Of T), that instance is an iterator. You can iterate through the collection by calling MoveNext on the enumerator and looking at the Current property until you’ve run out of values. Or you can use the For Each statement, which will do the iteration for you.

It’s possible to construct iterators in Visual Basic today–all you have to do is implement IEnumerable(Of T) and then implement IEnumerable(Of T). But the problem is that doing this involves a whole lot of boilerplate code that is the same in almost all iterators. On top of that, if an iterator involves a lot of conditions or branching, doing state management can be quite tricky. In an ideal world, what you’d like to be able to do is simply state the values that should be iterated over and have the compiler generate all the boilerplate code and state management for you. C# does this through the yield statement, which can be used in a method that returns an iterator to automatically generate the iterator:

using System;
using System.Collections.Generic;

class Program
{
    public static IEnumerable<int> FromTo(int low, int high)
    {
        if (low <= high)
        {
            yield return low;
            foreach (int i in FromTo(low + 1, high))
            {
                yield return i;
            }
        }
    }

    static void Main(string[] args)
    {
        foreach (int i in FromTo(1, 5))
        {
            Console.WriteLine(i);
        }
    }
}

In this example, the FromTo method returns an iterator (typed as IEnumerable(Of Integer)) which is automatically generated by the compiler. What we’re considering in Visual Basic is essentially the same feature, but with a slightly different design. Instead of tying the iterator to a method, as in C#, we’re considering extending the multi-line lambda syntax that I talked about in the previous post to make “anonymous iterators.” The above example in VB would look something like:

Module Module1
    Function FromTo(ByVal low As Integer, ByVal high As Integer) As IEnumerable(Of Integer)
        Return Iterator
                   If low <= high Then
                       Return low
                       Return Each FromTo(low + 1, high)
                    End If
               End Iterator
    End Function

    Sub Main()
        For Each i In FromTo(1, 5)
            Console.WriteLine(i)
        Next
    End Sub
End Module

There are a couple of differences to notice here:

  • An anonymous iterator is just an expression, so it can be used as the return value of a function but could also appear as the target of a For Each, used in a LINQ query, stored into a field, etc. (This is particularly useful when a function produces an iterator and you want to do some validation. In the C# model, the validation code is not run until MoveNext is first called on the iterator, not when the iterator is actually produced.)
  • By default the type of the iterator is IEnumerable(Of T), where T is inferred from all the types returned from the iterator using the same algorithm we use for multi-line lambdas. You could also explicitly state the iterator type using an As clause, and we would allow IEnumerator(Of T) as the iterator type just like C# does.
  • We don’t require the yield keyword since we’ve already marked the block as being special by using a new contextual keyword Iterator. (There would also be an Exit Iterator statement, not shown.)
  • Our plan would be to add an Each operator that “unwraps” a collection and returns each of its values one by one. This is generally useful but also addresses some performance issues with nested iterators which you can read more about in Wes Dyer’s post on iterators. (It might also later allow things like unwrapping collections in collection initializers, like {1, 2, 3, Each a, 5, 6, 7}, where a is an array of integers or something…)

We’re interested in people’s feedback on this proposed design and any other comments you might have.

Lambda expression improvements

WARNING: This is a speculative post. Caveat emptor.

I haven’t finished reading through all the comments from my previous post yet, but I did think it was worth stating that we are considering improvements to lambda expressions in the next version. Specifically, we’re looking at allowing single-line lambdas that don’t actually return anything, something like:

Dim x = Sub() Console.WriteLine(10)

This was something we wanted to support in 2008, but just ran out of time for. We’re also thinking about multi-line lambdas that contain statements instead of just a single expression. So something along the lines of:

Dim y = Function(x)
            If x > 0 Then
                Return x
            Else
                Return -x
            End If
        End Function

Like C#, we’d infer the return type of a multi-line lambda by attempting to pick the best type of all the Return statements.

This is really a common request, so it’s definitely something we’re strongly considering.

A little update on VB10 thinking…

WARNING: This is a speculative post. Caveat emptor.

It’s been a while since I’ve had much of anything to say about our thinking about VB10 (well, it’s been a while since I’ve had much of anything to say) and I wanted to give a quick update on our thinking:

We also keep getting asked about:

  • Iterators. This is definitely on our radar but it’s a big item. We’re considering it, but it hasn’t been thought about nearly as much as some of the other things above…

Another thing that is on our radar:

And, of course, other stuff that will be talked about in good time…