Author Archives: paulvick

MustOverride and line orientation

One of the side projects that I’m working on in addition to this weblog is a managed scanner and parser for the Visual Basic .NET language. I started on the project because I’d really like to write some project analysis tools that I could use to determine things about how people use the language, but as it’s gone on I’m hoping to also release it into the community as a sample. (One of the wrinkles is that I’m “writing” the managed parser by looking at the existing unmanaged parser, so it’s not like the code I’m writing is completely of my own invention, although it is largely so.) I think that the more that people can work with a language in an automated way, and the more tools people can write for a language, the better it is for people who use that language. Anyway, we’ll just have to see. I still have to finish it first…

After I finished the scanner (scanners are easy), I started parsing expressions and have been working my way up the parse tree hierarchy. I’ve recently reached type members and, in particular, methods. An interesting thing is the way that VB’s line orientation interacts with MustOverride methods when parsing. In C#, parsing methods is pretty simple because after a method header you can see either a semicolon or an open curly brace. If it’s the former, then you’ve got an abstract method declaration; if it’s the latter, then you’ve got a concrete method declaration. Whether or not you specified abstract as a modifier on the declaration is really something for declaration semantics to sort out later on. In VB, though, the following fragment is ambiguous if you don’t look at the modifiers:

<modifiers> Sub Foo()
Dim Bar As Integer

In other words, once you’ve gotten through the method header, the next line starts with Dim, which could either mean that Foo was a MustOverride method and Bar is a field, or that Foo was a concrete method and Bar is a local. To figure out which is which, you absolutely have to look at the modifiers to see if MustOverride is there. This is the kind of thing that drives formal grammar writers nuts because it means you have to hork up your grammar productions to make it all come out right. It doesn’t make such a big deal, though, if you hand-code your parser, which is what we do for VB. (Hand-coded parsers vs table-driven parsers seems to be one of those religious arguments that language people get into. Let me just say I don’t take a formal position on the question.)

Interestingly, there are at least a few other places in the language (esp. in terms of object creation expressions versus array creation expressions) where things get complicated like this. But overall, it’s been pretty smooth sailing. I’ll let everyone know as the project progresses.

Yup, I did know that

Duncan points out a little something extra that VB.NET’s Try...Catch syntax supports. It’s something the underlying IL supports and it seems useful, so we figured, why not? A use that comes to mind is when dealing with COMExceptions:

Try
' Do some COM interop
Catch ex As COMException When ex.ErrorCode = &H80043919
' Handle this specific error
End Try

Nothing fancy, just a little something extra. An interesting thing to note is that the CLR doesn’t actually support specifying both a type filter (i.e. ex As COMException) and a filter expression (i.e. Where ex.ErrorCode = &H800043919), so the above Catch clause is a filter expression that checks both the type and the value together. It doesn’t use a type filter. I was never really clear why the CLR did it that way, but it’s not a big deal either way.

Best laid plans…

Before going to bed, I thought I’d check the logs really quickly to see if anything looked amiss, and, sure enough, I’d screwed something up moving to the new software. I’d been testing the new software at a different URL and forgot to tweak one of the settings when I moved it up to the root. As a result, the links for all the RSS items was messed up, which caused automated aggregators to start trying to fetch from the wrong location. It should be fixed now, I hope this hasn’t screwed anything up permanently.

New software

OK, as I previously threatened, Panopticon Central is now running on custom software adapted from the original BlogX codebase. I ended up rewriting a lot of the data caching behavior as well as adding a number of new features and making a few cosmetic changes. I hope everything will continue to work. Please leave comments if there are problems or things I screwed up.

The major changes that readers will notice:

  • The RSS feed has moved locations. The old location returns a permanent redirection and it seemed to work with SharpReader, so I hope it does with everyone else…
  • I added a comments RSS feed. Now you can thread comments using your aggregator, if you so wish.
  • The RSS feeds now return ETag and Last-Modified headers. I’m serious hoping this is going to cut down on the bandwidth.

Most everything else was internal. The major thing still on the “to do” list for external readers is Trackback support (and all related flavors of APIs). And I’m sure I’ll continue to fiddle with the internals. It’s a lot of fun.

Upcoming MSDN chat

Cameron’s blog also reminded me that we’ll both be participating in a chat (along with other team members) on Tuesday, July 29th, 2003. Do feel free to join us. Here’s the blurb, copied from Cameron:

http://msdn.microsoft.com/chats/

Date: Tuesday, July 29
Time: 1 PM to 2 PM
Title: Chat with the Visual Basic .NET Team: Language Design
Summary: Do you have questions about why Visual Basic .NET is the way that it is? Join Paul Vick, the architect of the Visual Basic .NET Language Specification, and other members of the Visual Basic .NET team for a wide-ranging discussion on the Visual Basic language. Learn the reasoning being the design choices and discover how to write more powerful applications.

I do have to say I find the summary a little frightening, though…. I hope I can live up to it!

Another VB.NET blogger

Another member of the VB.NET team has started a weblog, this one hosted on GotDotNet. His name is Cameron Beccario and he knows a whole lot about the language and the compiler as well. He was kind of bummed to find out that I’d already written about DirectCast, so I think what this means is that we’re going to be competing with each other to get the good tidbits about the language out before the other guy. And who wins, gentle reader? You do, of course!

What’s in a name?

What’s in a name? That which we call a rose
By any other word would smell as sweet.
– Romeo and Juliet, (II, ii, 1-2)

The name of this weblog is “Panopticon Central,” which is probably no stranger a name than some others, I suppose, but I still think bears some explanation. Like any good name, there are multiple levels of meaning, so to peel the onion from the inside out:

  • A “panopticon” was a kind of prison proposed by the philosopher Jeremy Bentham in 1791. (I don’t know if he actually coined the term or not.) The idea was to design the prison such that the guards would be able to observe the prisoners at all times without being seen. Thus, prisoners would never know whether they were being observed or not, and would be forced to moderate their own behavior. (At least, that was the theory. I don’t know that our modern technological panopticons work all that well in practice.) The name “panopticon” meant an “all seeing place.”

An odd choice, don’t you think, for a weblog name? A prison? Well, a step deeper:

  • For those of you who were not uber-geeks as teenagers, a little background about “Doctor Who.” It was a BBC sci-fi television show about a rogue Time Lord from the planet Gallifrey named “The Doctor.” Time Lords have the ability to travel through time and space in a machine known as a TARDIS (Time And Relative Dimensions In Space). On Gallifrey, the central complex that houses the Time Lords’ government is called the Panopticon.

Well, OK. In an earlier entry, I copped to be a Doctor Who fanatic when I was in my early teens. But why choose a Doctor Who reference several decades later? Another step deeper:

  • On my 13th birthday, two significant things happened: I went to see “Return of the Jedi,” which had just come out, and I got a 300 baud modem from my parents. At the time, of course, the Internet didn’t exist and dial-up bulletin board systems (BBSes) were the only game in town. Soon I was totally hooked and within a year decided that I wanted to run one. My parents procured me some BBS software a year later when they visited the Democratic presidential convention in San Francisco. A year after that, I managed to get them to give me a 10 megabyte hard drive for my Apple ][+ for Christmas (it had it’s own power source and everything!). Six months or so after that, my BBS went online. And because I was just coming out of my Doctor Who phase, it was called Panopticon Central.

My BBS lasted for two years until I went away from college and it was an absolutely wonderful experience. Besides being a lot of fun, it was a great way to meet a wide variety of people, some of whom remain good friends to this day. About six months ago, I was setting up my server and thought “Hey, it’d be cool to host my own domain.” But, of course, I needed a name and all the simple names were taken during the Internet Gold Rush. I toyed around with a number of other names, but kept coming back to Panopticon Central because it had good juju (at least, for me). When I decided to set up the weblog, it seemed a natural.

Ironically, the name appears to be particularly apt because weblogging has much of the same feel to it that BBSes did fifteen years ago. Same sense of community, same sense of individual investment, same pointless flame wars over obscure subjects… A bit like coming home after a long time away.

[An interesting sidenote about Doctor Who: in the show the Time Lords also maintain a large computer called The Matrix that contains all of the knowledge of Time Lords who have died. It also functions as a virtual reality machine which you can plug into, just like that other Matrix. During at least one adventure, the Doctor and his arch nemisis the Master are each plugged into the Matrix and the Doctor must fight his way out. And this was in 1975. The Wachowski brothers must have been fans too…]

Pulling on the loose thread…

Anand asks me in a comment whether I’m going to support TrackBack. It’s a very relevant question, as I’m currently neck-deep in a rewrite of the BlogX code to add a whole bunch of features that it currently lacks. In fact, I’m very lucky that my wife is also currently neck-deep in grading for the summer class she teaches, or else my disappearing into my study for long stretches of time during a weekend of beautiful weather would cause some marital friction…

This all started, of course, by pulling on a single loose thread on the sweater: in the immortal words of our current president, I “misunderestimated” how much interest my blog might pull in, so each day I’ve been watching a bit alarmedly as the amount of my bandwidth being eaten up by the blog has grown and grown. I finally turned on gzip compression in IIS (I believe), which should help, but what I really wanted to do was implement ETags and Last-Modified on my RSS feed so I can cut down on the huge amount of bandwidth that SharpReader is sucking up. (They’re, like, 50% of the hits. Good for Luke… I use it too!) So I figured, “Hey, it’s .NET and I work on .NET. How hard could it be?” Classic last words for a developer.

The first problem was that, as much as I like C#, I just think a whole lot better in VB because I don’t have to translate as I work (and I like the VB IDE experience better, but I may be sliiighly biased). So first I translated most of BlogX (everything except the HTML control for WinBlogX) into VB using an automated translator. And then I spent a bunch of time cleaning up all the problems and stylistic disagreements that that caused. And then I spent a bunch of time cleaning up the code base so that it worked “the way I like it.” (This is no knock on Chris, I’m just one of those anal developers who just aren’t happy if they haven’t rewritten most of any codebase they take on.) And then I finally got around to trying to add new features. Which of course made me realize I didn’t understand how the whole thing worked, which entailed more research and rewriting, blah, blah, blah, blah.

Suffice it to say, I’ve devoted way more time to this than I had ever planned and still haven’t gotten a fully functional blog working. But I’m getting close! And soon this blog will have all kinds of whizzy-bang features. And I’ll have learned a whole lot of things about web programming that I never knew, which was really kind of the original point anyway.

And then Dare will release a new version of BlogX with all the features I added and many more to boot, and I’ll wonder, “Was it really worth it?”

Language divergence

Eric points to an editorial from Visual Studio Magazine that I think is really spot-on, although I think the title is a bit of a misnomer.

Patrick is, I think, accurate about some of the whys and wherefores of VB.NET’s history, and about the need to recapture some of what has been lost in the transition to .NET. There’s no question, for example, that not having edit and continue has been a huge loss, something that has been keenly felt within the company as well as without. It’s going to be a major feature in Whidbey and one I’m very excited about getting back. (I’d better be, since one of the things I’m supposed to do is make sure we do edit and continue right. If it’s wrong, my head is going to be one of those on the block…) And there’s even more stuff that we’re working on in addition to that, but we’ll get to that later, I hope…

The only issue I have with the editorial is the use of the phrase “language divergence.” The phrase is problematic because it’s so general that it can mean a lot of things that are not what we’re working towards. For example, it doesn’t mean that VB.NET is going to stop providing excellent support for the platform. It also doesn’t mean that we’re going to try and “dumb down” the language or compromise on the power and flexibility that we afford developers today. What it does mean, to us at least, is that VB is not just “C# without braces.” Our goal is not to just ape whatever another language does, our goal is to server our customers as best as we possibly can. If that means that we do some things differently than C# does, then we’ll do them differently. If that means we do some things the same way as C#, then we’ll do them the same way. Some people (not Patrick) have used “language divergence” as a shorthand for a mindless “not C#” philosophy, which would be incredibly short sighted and is not what we’re doing. Just as C# borrowed a ton of concepts that VB made popular, we feel free to borrow their best ideas right back. Why not, if it helps our customers?

So, in the end, I think the whole “C# vs VB” argument is a non-starter. The real question is: are we doing a good job making your life easier? Are we the best tool for developers out there? That’s the important thing and what we focus on every day.

Dictionary lookup operator

I’ve been converting some C# code into VB (because I think better in VB than I do in C#), and the conversion reminded me of another small feature of VB that people tend to forget about. Everyone who’s used Access or VB probably is familiar with the ! operator. Most of the time, you probably used it with DAO/ADO, something like: (Forgive me if the methods are wrong, it’s been a while since I wrote any non-ADO.NET code.)

rs.AddNew()
rs!CustomerName = "John Smith"
rs!Address = "10 Main Street; Seattle, WA"
rs!Phone = "(206) 555-1212"
rs.Update()

You probably used the ! operator because you saw someone else using it, and it was a lot easier than writing rs.Fields("CustomerName") = "John Smith". But you probably never thought about what, exactly, the ! operator was doing. Sadly, the operator has fallen somewhat into disuse because of the advent of strongly-typed datasets in ADO.NET. But it’s still quite handy!

The technical name for the ! operator is the “dictionary lookup operator.” A dictionary is any collection type that is indexed by a key rather than a number, just like the way that the entries in an English dictionary are indexed by the word you want the definition of. The most common example of a dictionary type is the System.Collections.Hashtable, which allows you to add (key, value) pairs into the hashtable and then retrieve values using the keys. For example, the following code adds three entries to a hashtable, and looks one of them up using the key “Pork”.

Dim Table As Hashtable = New Hashtable
Table("Orange") = "A fruit"
Table("Broccoli") = "A vegetable"
Table("Pork") = "A meat"
Console.WriteLine(Table("Pork"))

The ! operator can be used to look up values from any dictionary type that indexes its values using strings. The identifier after the ! is used as the key in the lookup operation. So the above code could instead have been written:

Dim Table As Hashtable = New Hashtable
Table!Orange = "A fruit"
Table!Broccoli = "A vegetable"
Table!Pork = "A meat"
Console.WriteLine(Table!Pork)

The second example is completely equivalent to the first, but just looks a lot nicer, at least to my eyes. I find that there are a lot of places where ! can be used, especially when it comes to XML and the web, where there are just tons of collections that are indexed by string. One unfortunate limitation is that the thing following the ! still has to be a valid identifier, so if the string you want to use as a key has some invalid identifier character in it, you can’t use the ! operator. (You can’t, for example, say Table!AB$CD = 5 because $ isn’t legal in identifiers.) In VB6 and before, you could use brackets to escape invalid identifiers (i.e. Table![AB$CD]), but when we started using brackets to escape keywords, we lost the ability to do that. In most cases, however, this isn’t too much of a limitation.

To get really technical, x!y works if x has a default property that takes a String or Object as a parameter. In that case, x!y is changed into x.DefaultProperty("y"). An interesting side note is that there is a special rule in the lexical grammar of the language to make this all work. The ! character is also used as a type character in the language, and type characters are eaten before operators. So without a special rule, x!y would be scanned as x! y instead of x ! y. Fortunately, since there is no place in the language where two identifiers in a row are valid, we just introduced the rule that if the next character after the ! is the start of an identifier, we consider the ! to be an operator and not a type character.