Author Archives: paulvick

Here we go again…

Not content to leave well enough alone, I’ve continued to hack away at the OpEd codebase to try and add some features that I thought would be useful. I’m now trying them out live, so if there are any problems, do let me know. Major changes are:

  • The backend storage is now a SQL Server database instead of an XML file. No one should really notice this, I hope.
  • I merged “comment view” into “permalink view” and added a permanent redirect from the former to the latter. I didn’t see much point in not showing comments in permalink view.
  • Every item now has a Trackback URL. I hope it works – I tried it out locally, but the world seems to be a variable place. Autodiscovery of TrackBack from RSS and embedded RDF in the page should work too.
  • I now generate dc:creator tags in the RSS, so names should start showing up in SharpReader.

I think that’s the major stuff. I’ve already had to fix a number of glitches since going live, so I won’t be surprised if there aren’t a few more disasters lurking around the corner…

Accessing shared members from instances

OK, quick quiz. And, yes, this is a trick question. Without looking at VS, what do you expect the following code to print?

Public Sub Foo()
Dim s1, s2 As String

s1 = "abc"
s2.Copy(s1)
Console.WriteLine(s2)
End Sub

Yes, that’s right, it prints nothing. Wha….? Because String.Copy is a shared function that takes a string and returns a copy of it. It has no effect on the instance that it’s being called on.

Another quick quiz. And, yes, this is also a trick question. Without looking at VS, what do you expect the following code to print?

Public Class Foo
Public Shared Baz As Integer = 10
End Class

Module Test
Public Function Bar() As Foo
Console.WriteLine("abc")
Return New Foo()
End Function

Sub Main()
Dim y As Integer

y = Bar().Baz
End Sub
End Module

Yes, that’s right, it prints nothing. Wha….? Since Baz is a shared member, we do not need to evaluate the qualifying instance expression, so we don’t. So Bar is never called.

In general, it is a bad idea to call shared members off of instance expressions for these two reasons. Shared members cannot affect instances directly, so calling shared methods or changing shared properties/fields off of an instance may give surprising results. And because we do not evaluate expressions that qualify shared members, you won’t get side effects where you might expect it. (This has bitten even a few members of the VB team themselves.)

A legitimate question then is, if it’s a bad idea, why do we allow it in the first place? Unfortunately, the original logic has been lost to history – my grey matter no longer contains the memory of when and why we decided to allow this. One possible reason is that disallowing shared member access off of an instance expression causes problems in a common situation:

Enum Color
Red
Blue
Green
End Enum

Class Control
Public Color As Color = Color.Red
End Control

With just the simple rule that shared members cannot be accessed off of instances, the field declaration in Control would be in error. This is because the Color in Color.Red will bind first to the field Control.Color, which is an instance field. Which means you can’t access shared members off of it, and enum members are shared. C# fixes this problem by introducing a special rule: in a context where the name of a variable is the same as the name of its type, you can access shared instances off of an instance. As it turns out, we had to introduce this rule anyway late in VS 2002 for the following related situation:

Class Control
Public Color As Color

Public Shared Sub Bar(ByVal SomeControl As Control)
SomeControl.Color = Color.Red
End Sub
End Class

In this case, the Color in Color.Red still binds to the instance field, but you run afoul of the rule that says that you can’t access instance members in a shared context.

Whatever the original logic, it’s become clear that this is not a good design and that we made a mistake in allowing it. (Yes, Virginia, we do make occasionally make mistakes around here.) I encourage people to avoid using it whenever possible. Unfortunately, the compiler doesn’t really help you on this today, but it’s something we’re be helping you more with in the future.

“The only emperor is the emperor of ice-cream.”

[Ed note: Warning. No technology content ahead. May not be suitable for all readers.]

Well, I’ve finally broken down and installed the RealPlayer so that I can listen to The Writer’s Almanac on my computer every day instead of mostly missing it on our local NPR station. What I find fascinating about it is that it manages to bring poetry back from the obscure backwater that it inhabits in my high school English classes of the past. What’s even more fascinating is that normally I absolutely cannot stand to listen to Garrison Keillor do a reading – his “News from Lake Wobegon” segment from A Prairie Home Companion is like nails on a chalkboard to me. But for some reason I think his poetry readings are just absolutely superb. It’s probably because he lacks that self-conscious “poetry cadence” that most people (including poets themselves) use when reading poetry. I think the poetry choices are also very good and I have found the poems he reads to be very personally affecting, something that I had really forgotten that poetry can do. Many kudos to a fine and worthy effort.

And for those who wonder, the title of this entry comes from one of my favorite poems (do people still have those these days?), “The Emperor of Ice Cream” by Wallace Stevens. Why it is a favorite, I have no idea. Something about the line “Let be be finale of seem” just does it for me, I guess…

[We now return you to your regularly scheduled technology blog.]

What’s an ideal BMI?

Erik posted an entry talking about an introduction he wrote for a forthcoming C# textbook, and he says:

Many computer books are so heavy that lifting them cause hernia [sic], yet they have less content than your favorite tabloid.

Which made me think about something that I worry about: what’s a good BMI for a book? (By BMI, I mean the fictional Book Mass Index, a related measurement to the human Body Mass Index.) Namely, will people not buy a book if it’s not hefty enough?

As I’ve mentioned earlier, I’m working on a language reference book for VB, something like a K&R or Stroustrup for the VB .NET language. (Whether it succeeds in reaching that lofty goal still remains to be seen.) One thing I continually worry about as I write it is whether the book is going to look good sitting on the shelves between all those behemoth VB books that Barnes and Noble seems to stock. With a mostly-done first draft, it currently clocks in at less than 300 pages, which means it’s going to be puny in comparison, even given some inevitable expansion as I fill in some holes I left in the draft. I’d like to think that it’s just that I’m packing in more information-per-square-inch than other books, but I don’t know.

One thing I’m still debating on whether to add to the book is a section on the VB runtime functions (Left, Right). Technically, they’re library functions, but they’re so closely identified with the language that they are as good as part of it. If I did that, they’d definitely pad the book out nicely (Gosling et al. used this to great effect in their Java book). Of course, that would also mean I’d have to write it.

Ultimately, I think it gets back to something I had to come to terms with when I started working out a few years ago. Being a somewhat competitive person, I would keep track of how I was doing relative to other people in the gym, but over time I observed that no matter how fast or strong or flexible I got, there always seemed to be someone who was a whole lot faster or a whole lot stronger or a whole lot more flexible than I was. I finally decided I either had to quit comparing myself to others altogether and just be happy with my own progress or I had to quit working out. I figured the former was the better option…

Is it better to be smart or dumb?

Chris points to an article that I saw talked about in the New York Times or some such place in the somewhat distant past. It reminds me of a story that my wife tells about when she was young and her sister asked her grandfather, “Papa Ali, is it harder to be smart or dumb?” His reply (more or less) was “It’s harder to be smart. You see, dumb people don’t know they’re dumb, so it doesn’t bother them. But the smart people have to deal with the dumb people.”

The implication, though, of this article is that the answer really is “neither,” because if dumb people don’t know they’re dumb and think they’re smart instead, they’re going to get just as annoyed by the supposedly “dumb” people they deal with.

As for me, I take no position as to which category of people I fall into. Safest position to take…

“It’s such a fine line between stupid and clever.”

Joel’s foreward to Rich Chapman’s book In Search of Stupidity resonates with me because it’s what I’ve always said about Microsoft: it’s not that we’ve been so much smarter than our rivals over the years, just merely that we’ve been less stupid. Joel says that the worst mistake Microsoft’s made has been the dancing paperclip, but that’s not really true. I can think of a legion of boneheaded, wrongheaded and just plain dumb things that Microsoft has done, large and small, since I first came to work here. Microsoft Bob jumps to mind. Or the first, oh, I don’t know, five years of MSN’s life. Or the Tiger media server – we must have dumped a lot of moolah down that black hole. And for all the public failures that we’ve had, there are plenty of internal screwups that never make it to light.

One thing I think that has made more difference than anything else was the fact that Microsoft tends to be pretty dogged about following the old maxim “if at first you don’t succeed…” Plenty of eventual success stories at Microsoft started off life as fiascoes, but we kept plugging away at them until we made them work. Through the years, I’ve been amazed at the way that major competitors who could really give us a fight in some area seem to lose interest once we start to do well against them. (OS/2 springs to mind.) I sometimes wonder if Bill knows the secrets of the Jedi… “This is not the market you are looking for. We can go about our business. Move along.”

There are two kinds of people in this world…

…those who think Edit and Continue is a good idea and those who don’t. I still haven’t gotten to answering Franz‘s original question, but a recent entry he made does start to address the question.

I totally understand what he’s saying when he talks about the fact that Edit and Continue allows for some very bad programming habits. I spent a few summers teaching teenagers to program, and I got to see first hand some of the ways that bad habits can derail programmers, especially new programmers. From a theoretical standpoint, it is infinitely preferable for programmers to follow the well-worn steps to programming nirvana: understand the problem, design the program structure, implement the program, test the program, fix the bugs, ship the program. In that order.

And yet… The reality is that life is messy and does not always conform to theoretical norms. I am a skilled programmer who works on a major product produced by a large corporation. But even I have lots of times where the code that I write only needs to be “good enough” and not brilliant. I’m not talking about the VB compiler here – obviously, that has to be brilliant – but about all the side projects and throwaway tools and prototypes and test cases that I work on in my day to day life. It doesn’t matter that they’re well designed, only that they work.

And that’s what makes Edit and Continue so wonderful. When I need to bang something out rapidly, I can design the application on the fly. I outline the application, hit F5 and I’m off, writing the code as I go along. If I made a mistake, no problem, I can fix that on the fly without having to restart the entire application. If I’m working on something that really needs to be polished up later, that’s cool – I can do that later. But for now, I’m getting my work done and I’m doing it without all the theoretical design overhead that I really don’t need at that moment. And there are a lot of people in this world who just need to get their work done like this and don’t need to produce well-designed, meticulously thought-out applications. That’s why Edit and Continue is such a big feature for them.

(I’ll also add that I suspect that many, but certainly not all, developers who do not want Edit and Continue haven’t really tried it. Even for people who think fully through their design and eschew debugging on the fly, there is always those times when you hit an exception 10 minutes into running your application and you realize that you just forgot to initialize some stupid variable. If only you could just fix that one damn line and not have to re-run the application again for 10 minutes… If only…)

Anyway, like I said, I’ll freely admit that EnC can enable people to slide by with some pretty bad habits. But if people find it useful, why not do the feature and allow people to decide for themselves whether they’re going to have bad habits? The purpose of a tool is not to make people use it in the “correct” way, the purpose of a tool is to assist people in getting something done. That means that just because someone might misuse a feature does not, in and of itself, mean that you shouldn’t do it. This is really a core philosophy of VB: whatever it takes to give you the shortest path between your idea and a completed application. That’s RAD.

Whidbey and Orcas roadmap

Thanks to Scott and Sean for pointing out that MSDN has published a high-level roadmap for Whidbey and Orcas. I’m planning at some point in the near to talk a little more about some of the details of Whidbey features, especially generics. Not because I have an urge to blab secrets but because I think there’s value in letting people know where things are headed, and even get a chance to get some feedback.