Archive for September, 2005

VB.Net Keywords

Wednesday, September 28th, 2005

The VB.Net grammar has always had, at least for me, a strange approach to keywords. In contrast to many languages, VB allows you to, at least at the syntactic level, use keywords for identifiers in many situations. I guess it may have been to allow maximum operability with libraries implemented in other .NET languages.

The latest spec removes a lot of keywords while retaining their use within the grammar. C# also uses this technique of “context sensitive keywords”. Overall it’s a bit of a pain as you generally need to play games between the lexer and parser stages to make it work. Today I’m going to look at the preserve keyword which is, alas, not preserved.

A long time ago, in University, I used a book “Principles of Programming Languages” by Bruce MacLennan. It’s way out of date by now but I remember still how it put forth a set of priciples for langauge design including classis such as the zero-one-infinity principle. Anyway, one of the principles was “The regularity Principle: regular rules, without exceptions, are easier to learn, use, describe and implement”

The dropping of preserve as a keyword allows us to create a program which, I think, violates this principle:

Imports System

Module Test
Public Sub Main()
Dim preserve(2, 2) as integer
redim preserve(2, 4)
End Sub
End Module

This will not compile with my current version of vbc 2.0. If I change the name of the variable, however, it will. Isn’t that odd? I’m not sure of the motivation for removing the keywords when it really does seem to want to be a keyword.

C# 2.0 parsing

Wednesday, September 28th, 2005

I have recently been working on the parsing of C# and VB.Net as part of our development of Clover.NET for Visual Studio 2005 and .NET 2.0. I think it is fair to say that the changes to the language specs for both languages have increased the complexity of parsing both languages quite significanly. Over the next few days I’ll post some example code snippets that show off some of the problems we have encountered in testing our parsers for the new language features. If I get time I also want to discuss some of the general techniques we have used to simplify parsing.

To start with, today I’ll give a little example program which will compile with csc 1.1 but which fails to compile with csc 2.0 (I’m using the July CTP at this time). This example is inspired by the examples in the C# specification of March 2005 and centres around the ambiguity of the >> symbol in the presence of generics (I have to work hard not to type “templates” there). If I read the spec correctly, this should compile ok but, so far, Microsoft disagree and class this compatibility breakage as “by design”.

using System;

class X
{
static void Main ()
{
X x = new X();
x.runTest();
}

public int F(bool a, int b) {
return 2;
}

public void runTest() {
int a = 5;
int b = 6;
int c = 7;

int blah = F(a<b ,c>>2);
Console.WriteLine("Blah = " + blah);
}
}

The csc 2.0 compiler interprets the arguments in the call to F to be a generic, rather than two separate arguments. I guess it’s not a big deal in practice as the example is somewhat contrived. Nevertheless, I find the compatibility break disturbing.

Subversion Property Naming

Thursday, September 1st, 2005

As part of developing Subversion support for FishEye, we were concerned about the ability of just anybody to hook up a FishEye instance to a public Subversion repository. If enough people attached FishEyes to a repository it might have an impact on the server load. In contrast to FishEye for CVS, FishEye for Subversion uses the standardSubversion supported network protocols to access the server. This means that a public Subversion server is available to anybody wanting to run FishEye against that server.

To give repository owners some control over this access, we added a check in FishEye for an access control property. In the upcoming beta, this will be a fairly simple check to see if FishEye is granted access or not. In the future it will probably be a little more sophisticated.

Our initial implementation was to call this property fisheye:access. It seems natural to choose a scheme which is similar to the scheme used by Subversion itself, with such properties as svn:mime-type and svn:author, etc. When you do use that scheme, however, and your repository is accessed over http, the resulting XML documents used by DAV are not well formed. In particular, you may end up with something like this:

<C:blah:test>test2</C:blah:test>
<C:blah_test>test</C:blah_test>

The first label is not well formed XML in a namespace aware XML document. This errata for XML names clarifies as follows:

” It follows that in a namespace-well-formed document … All element types and attribute names contain either zero or one colon; ”

We’ve found that when Xerces encounters these names, it maps the colon to an underscore. The above two properties, blah:test and blah_test, coalesce into a single property value blah_test.

We have now decided to change to fisheye.access to ensure we don’t run into problems for people with strict XML parsers. The native XML libraries usd by Subversion seem to handle this problem without concern. They are probably a little bit loose in their XML handling. It’s debateable whether such looseness is a good thing or not.