Rants on JDK1.5 Generic Types Variance

11 PM June 26, 2003

Rant One

Matt Quail, points to Sun’s Bug Parade evaluation of variance, in which a Sun representative states:

Based on feedback within Sun, we are unlikely to do this for Tiger.

What does “Based on feedback within Sun” mean? It could mean any of:

  1. We found it an unsound concept, but are too embarrassed to admit it.
  2. There are so many bugs in our reference implementation that fixing them would compromise the Tiger release schedule.
  3. Scott McNealy decided the name “variance” sounded wishy-washy and canned when he came in this morning.

Most likely, it means none of these. The point is that uninformative statements like “based on feedback within Sun” make it very clear that Java is Sun’s game and nobody else’s. Sometimes their decision making process is in the open, sometimes it’s closed, but Sun make the rules and we just have to trust them if we want to be on the Java bandwagon.

Rant Two

Commenting in Matt Quail’s blog, Mats Henricson rightly points out that the type safety argument is a red-herring.1

On the other hand, there are other, real benefits to be had from more being explicit about the type of collection variables:

  • More economical code. Java code with generics is less cluttered and easier to understand than Java code with casts.
  • More meaningful interfaces, due to explicitly typing the contents of collection parameters. CASE tools (including IDEs) can be more helpful to programmers. It also reduces the amount of information that needs to go into Javadoc.
  • Removes most of the need for arrays, and constant kludgy conversions between arrays and collections.
  • Generic collections are simpler to teach than standard collections and casting.

I’ll be happy to see casting go. It’s always been the ugliest part of day-to-day Java coding2.

PS: Every argument for not explicitly typing all variables in Java is an argument in favour of Python.


1 Me too.

2 Not counting add-ons like JSPs and EJBs.

By alang | # | Comments (0)
(Posted to Software Development)

Comments

Add Comment




(Not displayed)






(Leave blank line between paragraphs. URLs converted to links. HTML stripped. Indented source code will be formatted with <pre> tags.)




© 2003-2006 Alan Green