Archive for April, 2005

Interface Evolution and Exceptions in Java

Thursday, April 14th, 2005

I’m firmly in the camp that favours the checked exception style used in Java as opposed to the unchecked approach used by C#. For me it’s as fundamental as explicit declaration of variables. Java is, in general, a statically typed language and, for me, checked exceptions are part of that style. It’s a different story in more dynamic languages such as Python. I do recognize, however, the fact that some people have strong opinions to the contrary and I’m not out to convert anyone here.

I have come across an issue where the explicit declaration of exceptions does cause a problem. Today, when you declare in Java that your code throws a particular exception, you can never take that away that without breaking somebody’s code. You can’t evolve the interface in a graceful way. A recent case in point involved a seemingly innocuous change to BCEL. The signature of a constructor changed from

public ClassParser(String file_name) throws IOException

to

public ClassParser(String file_name)

Unfortunately that broke the following code in Ant, since the compiler says, quite rightly, that the code does not throw an IOException.


try {
new ClassParser("force");
} catch (IOException e) {
// ignore
}

Here is the crux of the problem. If we changed Ant’s code to work with the new BCEL code, then Ant would not be compilable against the old BCEL. Ant’s and BCEL’s releases would need to be synchronized which is not a good thing.

I added the exception specification back in to the BCEL code but it’s not a very satisfying approach. The BCEL constructor doesn’t throw the exception anymore and there should be a way of saying so, of evolviong the interface gracefully. The best idea I could come up with was adding something like a @deprecated_throws indication which indicates that the method used to, but no longer, throws a particular exception. The compiler would emit a deprecation warning on any code that caught this exception. As with other deprecated usages in Java, it would not cause an error. Such a mechanism would allow Ant to compile with both the old and the new versions of the BCEL code. The Ant and BCEL releases would be decoupled and sufficient time would be available for the BCEL change to propagate through its users.

JUnit Manifest – Why no MainClass?

Wednesday, April 13th, 2005

Time for a minor rant.

Why doesn’t the jUnit jar have a manifest with a MainClass atrtibute? Surely there is some useful default application that junit could run in this instance – I don’t know – maybe the Swing GUI test runner. It would sure save me looking up and typing the class name on the occasions I need to run a test outside Ant. Has further JUnit development stopped?

Oh well, back to those tests …

Update: OK, I can think of a few reasons :-)

More MT to WordPress Rewrites

Tuesday, April 12th, 2005

As I noted in a previous entry, I used the Rewrite rules suggested by DrBacchus. I’ve just now updated them to handle the monthly archives as well as the single article archives. I also made these rewrites work as permanent redirects. Javablogs updated my feed info automatically which was nice. Here are the rewrites I am using:


RewriteRule ^blog/archives/(200.)_(..).html$ /blog/index.php?m=$1$2 [R=301]
RewriteRule ^blog/archives/00(.*).html$ /blog/index.php?p=$1 [R=301]

mod_rewrite rocks.

Clover.NET 1.2 Released

Monday, April 11th, 2005

One of the reasons I had time to update my Blog software is that we, Cenqua, have recently released Clover.NET 1.2. There’s lots of good stuff in it but I won’t go into most of it here. Have a look at the announcement in our forums for more info. What I thought might be interesting to talk about are the issues in parsing VB.Net.

When we started to add VB.Net support to Clover.NET, I thought parsing VB.Net would be relatively easy. After all, on first inspection, for most statements, there is a corresponding “End” statement. I thought that the regularity that implied would make everything quite simple. If only it were so …

We started from the Microsoft VB.Net language specification and it’s a good start. Defining a grammar for a language parsr, however, is a precise art and it soon turns out that the real specification of VB.Net is the set of programs which can be compiled by vbc and not that specified by Microsoft’s grammar. Since releasing VB support, we’ve had a few reports of programs that out parser rejects. In most cases, we’ve found the program does not meet the language spec but it is accepted by vbc.

One example would be the specification of EventMemberSpecifiers. In the specifcation, the event specifier takes an Identifier. In reality, this can be either a keyword or an identifier. So, even though “select” is a keyword, the following is ok


Private Sub MenuItem1_Select(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem1.Select

End Sub
Since the MS grammar is explicit in other areas about allowing keywords or identifiers, it makes you wonder why it does not allow that here.

The ability to use keywords as identifiers is pretty unusual in a language. I wonder if that is a result of .NET’s multiple language ideas. It certainly makes parsing a challenge.

Another example is the block construction. A block is defined as a collection of one or more labeled lines, each of which must end in a LineTerminator, which is a CR or LF one one of the Unicode variants. So, when a TryStatement is specified to take a block, this should not be legal but is:


Try : stream.Close() : Catch : stream.Close() : End Try

So, a block can be terminated by a colon too, which is unfortunate as the colon is used for a few other things too.

Anyway, you get the picture. If you are parsing VB.Net, and using the specification as your guide, you’re in for a few surprises. It’s what makes life interesting, isn’t it?

Updated My Blog Software

Monday, April 11th, 2005

I’ve finally updated my Blog software. It took me a while. I looked into a few packages and finally chose WordPress. It seemed to have all the features I needed and is provided as an option by my hosting provider, which is nice but not a major factor.

I’m hopeful the change should be relatively seamless. I have redirects in place for the old MovableType pages and feeds. It took a bit of hacking to get right. I worked on my Fedora box, using a site backup to test out the various options. I learnt a bit about Rewrite rules in the process. Thanks to DrBacchus’s Journal for some useful information.

Of course, the main feature I was after was the measures to avoid comment and trackback spam – we’ll see how that goes. It’s ironic that as I was thinking about upgrading, WordPress.org ran into some bad PR, relating to gaming Google. After reading the various explanations, I was happy to go ahead with WordPress. Everyone makes mistakes …