Author Archives: paulvick

Language wars and Kilkenny cats

I try to stay out of the language wars as much as possible, and I’ve particularly sat this round out because it was started by a company who’s trying to sell something. However, the word that A Word A Day sent out today seemed strangely appropriate. The word was “Kilkenny cats” and you can read more about them here. I particularly liked the limerick:

There wanst was two cats of Kilkenny
Each thought there was one cat too many
So they fought and they fit
And they scratched and they bit
‘Til instead of two cats there weren’t any.

Appropriate…

Why don’t partial types require partial on all declarations?

Andy Maggs asks:

Who thought it was cool to be able to create partial classes without indicating on the ‘primary’ class that it has other parts somewhere else. In C# you must use the partial keyword on all parts, so why not VB?

Since partial type cannot span projects (i.e. a type must be fully described inside of a project), we felt it was sufficient to only have to have at least one of the declarations “opt in” to partialness. Requiring every partial declaration to have to specify that it was partial seemed to be unnecessarily strict. For example, in the designer case such as a WinForm, it is really necessary to put “Partial” on the class declaration when the partial type that the designer spits isn’t even shown by default?

And, of course, there’s no reason that a developer can’t specify “Partial“ on all partial declarations if they so choose. You can even modify, say, the WinForms template to add it if you want.

In the end, this is one of those things I was talking about just last week, a real judgement call. There are more than a few people who have taken issue with this particular decision, feeling that the more explicit the better. (There have been even suggestions made to us that partial types should have to explicitly state which source file the other partial types reside.) I can see their point and don’t think their arguments are bad, we just don’t happen to agree on this…

Boo to you, too!

Don pointed to the release of a new .NET programming language called boo. I downloaded the boo manifesto and took a look and it seems very interesting (and it’s nice to see some language experimentation going on on the CLR!). Some of the ideas aren’t unfamiliar – C# already has iterators and we’ve kicked around the idea of being able to enable late binding on a per-variable basis (called “duck typing” in the manifesto) – but others are less familiar. One idea I’m curious about seeing how it plays out is extensibility in the language. In the manifesto Rodrigo says:

I wanted a language I could extend with my own constructs.

This is one of those ideas that’s always seemed to me to be great on the face of it but questionable because of the law of unintended consequences. On the one hand, how can you argue with giving people the ability to extend the language as they see fit, especially given the fact that compiler releases can be a year or more? On the other hand, it’s so easy to screw up language design even when you’ve been doing it a long time that I wonder if you won’t quickly have a language that’s no longer comprehensible by man or machine.

One thing that Rodrigo loves about .NET is the nice way that the entire set of class libraries are architected together in a pretty clean and consistent manner. This is a great advance over the hodgepodge approaches of the past where fundamental libraries were incompatible or worked in entirely different ways. I wonder, though, if allowing extensible languages isn’t taking a step backwards into that world. Central control of a language ensures some reasonable amount of consistency in thought and design – if anyone is allowed to add extensions, will the language gradually devolve into the language of Babel? Or will only extensions that preserve the core style survive while the others die off? I guess we’ll just have to see.

I will add that one major problem with our compilers today is that entirely too much information is locked up in them. We’ve started exposing compilation information through mechanisms such as the Visual Studio code model, but we need to go a lot further to enable more advanced and extensible tools. It’s certainly possible to expose a lot more information about what exists in the code that’s being compiled without having to make that information modifiable outside of the compiler, and I think that’s something that’s unquestionably worth pursuing in the long run.

Zero-impact projects rock!

OK, I’ll admit it – there are actually times when I think features that we’re introducing are stupid. (Of course, they’re always someone else’s features, never my own…) One such example was the reappearance of something we call “zero-impact projects.” A zero-impact project is a project that is created on-the-fly in a temporary directory rather than being saved somewhere permanent like your Projects directory. You don’t have to create something permanent until you do something like shut down the IDE or close the project. VB6 did this, but VB7 didn’t, and I personally never thought much about it. When I found out we were doing the work to restore it, I though, “Ah, that’s dumb. Who really cares about this? All it does is save you having to pick a place for your project… Grumble, grumble.”

Well, let me publicly eat my words: munch, munch, munch. I’ve switched to VB 2005 Beta 1 full time for the stuff that I’m working on and zero-impact projects absolutely rock! One of the things I’m doing right now is updating the language specification for VB 2005 and it’s just great to be able to bring up VS, create a VB project, play around for a little while and then close down VS without having anything left behind on my computer. No more “ConsoleApplication491349” projects! I mean, I was right in one way – it’s a little thing, but, boy, it does make a difference. (The faster startup time of the IDE also helps immensely.)

If you aren’t using the VB profile, you can enable zero-impact install by clicking on the “Projects and Solutions” entry in the Tools | Options dialog and unchecking “Save new projects when created.” It’ll even work for C# projects! (Although this feature might be a little too “edit and continue”y for those C# folks… <g>)

It’s all a matter of taste…

Eric and Cyrus have been expending a non-zero amount of energy trying to rationalize why they think static imports are bad. Maybe what they should do is just come out say “Hey, we just don’t like them” and then leave it at that. It seems like that would save everyone else a lot of energy arguing about what, in essence, comes down to a matter of taste.

VB has had static imports since VB 2002 and the world seems to still be turning happily on it’s axis. (Actually, in addition to static imports we have standard modules, which are even worse.) We haven’t been getting lots of complaints about unintelligible code being written because of it. We haven’t seen lots of horribly designed APIs being produced. Which isn’t to say that I don’t believe that there aren’t people out there abusing the feature (and shame on them!), just that by and large people seem to have taken the feature in stride and used it where appropriate. And I’m pretty confident that Java is going to see pretty much the same thing.

But, really, I don’t think it’s a horrible thing that C# doesn’t want this feature. As much as we like to dress up language design in processes and official sounding specifications, so much of what passes for language design comes down to the particular views of the particular people designing the language on some particular day. Language is almost infinitely malleable and often times the “best” way of doing something is not particularly clear – if you ask 10 different people about some particular design point, you’re likely to get somewhere between 8 – 10 different answers. Hell, if you ask the same person about some particular design point on two different days, it’s possible you’ll get two different answers. (It’s not like every single language team at Microsoft hasn’t backtracked on something at some point…) So even though rigorous intellectual analysis forms the foundation of language design, gut instinct (based on past experience, usually) can often be the decisive factor. And there might just not be any neat, logical, defensible reason why we choose to do this and not that, or implement something this way and not that way.

I think the same goes for stuff like the With statement, too. Although not everyone on the C# team might hold the same opinion on features like these, on the whole they’ve come to the conclusion that they don’t like the features, and I think that’s fair enough – they get paid to make those kinds of decisions, after all. It’s not like they haven’t bent over backwards to listen to community feedback and gone to great lengths to consider that feedback. It seems like in those cases a “Yup, we considered it, thought about it for a long while and ultimately decided it didn’t seem like a good idea. However, we’re always open to reconsidering the decision if things change.” would be sufficient….

(I will quibble with one of Cyrus’s points, though: I don’t believe that the Office API is the way it is because it was mangled to cater to the features of, oh, let’s be honest, VB. The Office API is in many cases the way it is because it had to be designed/mangled around the past limitations of the VB language. The Excel object model is so untyped in places because it was written before OLE Automation had type libraries and could express types other than VARIANT. All the Office applications abuse optional parameters to death because VB didn’t support overloading before VB 2002. And so on, and so on. The abuse of optional parameters is a particular shame because I think (and this is just personal speculation) that that is one of the reasons C# doesn’t support them. I can always hope they’ll see the light though…)

U.S.-centric dates and localized languages

Bill whinges a bit about the fact that date literals in VB are expressed using the U.S. date format, which is (of course) different that what most of the world uses. It’s a legitimate gripe, but there’s not much to be done about it. The cardinal rule that we follow with the language is that the current locale settings of a machine should never affect the compiler’s output. Thus, everything expressed in the language that’s processed at compile-time has to be in one canonical format and cannot be locale-dependent. And, of course, somewhere back in the mists of time when the canonical format was chosen, it just happened to be the format of the home country of the software… (This is also why you can’t do string conversions in constant expressions – string conversions are locale sensitive.)

It’s true, though, that the IDE used to be much more permissive about what it accepted as a date literal that you typed in (and which it would then convert to U.S. format). When we moved to .NET, we stopped using VarBstrToDate to convert strings that were input from the IDE and instead started accepting only legal canonical date strings. I don’t exactly remember why it was we did that, though…

I will add that VarBstrToDate is a very, very, very scary piece of code. As Greg Low notes in the comments on Bill’s entry, the old COM date conversions routines (on which IsDate is based) will do some truly wacky things. During the year and a half that I owned OLE Automation, I had to spend a good bit of time in the code for that routine and the finite state machine that it uses to try and recognize dates. Rather than just accepting the current locale, it has all kinds of weird logic to try and guess what you meant based on what’s possible. So if you call the routine on “24/1/04” using the U.S. locale, it’ll still parse it as January 24th, 2004 because it figured that the “24” is most likely a day value and that you were entering it in dd/mm/yy format. On the other hand, if you call the routine on “1/3/04” using the U.S. locale, you’ll always get January 3rd, 2004. Scary stuff.

(I also heard tell that at one point back in the mists of Excel 5 days, the VB team experimented with allowing the language syntax to be localizable. So you could say, I don’t know, “Por x = 1 a 5 : Escribe x : Siguiente x”, if you pardon my horrible Spanish. This turned out to be such a horrible idea that they quickly dropped it and never looked back. But supposedly the legacy lives on in OLE Automation and the fact that IDispatch takes a locale ID when converting names to DispIDs (i.e. so that you could have different method names for different languages). I can’t vouch for the absolute truthfulness of this story, but it’s one of those stories that’s “too good to check.”)

Upcoming VB 2005 language chat!

Just an FYI to everyone, the following chat is coming up on July 13, 1:00 – 2:00 P.M. Pacific time:

Visual Basic 2005 Language Enhancements
Visual Basic 2005 has many new and improved language features, including generic types, operator overloading, compiler warnings, partial classes, mixed access properties, unsigned data types, and more. Join members of the Visual Basic team to discuss these features. Provide the team with your feedback about the Beta version and get answers to your questions.

I’ll be there, I hope you will be too!

OutlookAdd to Outlook Calendar

Operator overloading in VB

One of the nice things about reaching beta is that we’re now starting to get more whitepapers out there on new features, which reduces the number of things that I feel guilty about having not blogged about yet. The latest example of this is a whitepaper on Operator Overloading in Visual Basic 2005 written by Matt Gertz, the development lead for the VB compiler (my old job, for those of you keeping score). It’s a great overview of what we’re doing with overloaded operators, so check it out!

Now we just need a whitepaper on generics…