Monthly Archives: November 2010

November 25, 2010
November 24, 2010

The Trouble with Checked Exceptions

A well-written article from back in 2003 where chief architect Anders Hejlsberg defends the lack of checked exceptions in C#.

It is funny how people think that the important thing about exceptions is handling them. That is not the important thing about exceptions. In a well-written application there’s a ratio of ten to one, in my opinion, of try finally to try catch. Or in C#, using statements, which are like try finally.

Site update

Finally, the day is here: posts whose titles links to external sites now do so in the RSS/Atom feeds, too.

November 16, 2010

Java: generics & superclasses

Generics in Java have always been both a source of fascination and frustration for me. I’ll openly admit that I still don’t know enough about the subject, even though I’ve worked with Java for four years now.

The very first thing that puzzled me is that contrary to “regular” classes in Java, generic elements don’t really have superclasses to speak of. Consider the following example:

Object obj;
String str = "Hello";
obj = str;

Naturally, a String has Object as it’s highest superclass. Thus, it’s legal to assign a String to an Object — obviously, one can only call the methods of the Object class after such an operation.

Now consider this example:

ArrayList<Object> listOne;
ArrayList<String> listTwo = new ArrayList<String>();
listOne = listTwo;
listOne.add(new Integer(1));
String str = listTwo.get(0);

In this example, we attempt to assign a list of Strings to a variable with the type “list of Objects”. If this would work, we could add another type of object (say, an Integer) to the list. After this, listTwo doesn’t just contain Strings anymore, which leads to trouble on the last line of our code. Thankfully, Java doesn’t allow this to happen — line 2 3 in our example will give us an error if we attempt to compile the code.

The best quick explanation of generics/superclasses in Java that I’ve found is in a book called Generics in the Java Programming Language (PDF link), written by Gilad Bracha:

For example, if the department of motor vehicles supplies a list of drivers to the census bureau, this seems reasonable. We think that a List<Driver> is a List<Person>, assuming that Driver is a subtype of Person. In fact, what is being passed is a copy of the registry of drivers. Otherwise, the census bureau could add new people who are not drivers into the list, corrupting the DMV’s records.

The book is a comprehensive Java generics resource, and discusses even the most advanced concepts in a highly understandable form. Don’t forget to read The Tapir’s Tale blog post or Angela Lanker’s website, either.

Fable III

Fable III is a mixed bag. Oversimplification of the user interface makes simple tasks a chore, but the voice cast and overall Englishness of the experience make it a worthwhile RPG.

The quest entitled “The Game” is the best quest I’ve played in quite some time.

★★★☆☆

November 12, 2010

Viacom to sell Harmonix

Bloomberg:

Viacom said today it will sell the unprofitable Harmonix unit, creator of the “Rock Band” music video game. Excluding the game business and tax benefits, profit was 75 cents, topping the 70-cent average of 26 analysts’ estimates compiled by Bloomberg.

It’s saddening to see that a high-quality franchise like Rock Band isn’t doing well financially.