Ugly, ugly, ugly . . .

A Standard Library Abomination

Conrad Weisert
Originally written February, 1996; minor format revisions and addendum 12 November 2009
©2009, Information Disciplines, Inc.

This article was a handout in an early Java course. It may be copied and distributed freely as long as the copyright credit is included

Background

We'd like to believe that the people who design the programming languages and other software development tools we use are top-notch professionals who understand long established principles of good programming practice. Unfortunately, we can't. Software technology is evolving so fast and new tools are appearing so often that major software vendors often have to entrust crucial design responsibilities to people who have little practical experience in large-scale high-quality software development.

Java's Date class is a sad illustration of this phenomenon. As part of the standard class library included with all Java 1.0 implementations this class ought to:

  1. support the functions a client-program might reasonably want to perform on dates,
  2. provide a coherent and consistent interface, and
  3. respect the object-oriented paradigm.

It fails on all counts, violating many principles of good programming and design.

How does this affect us?

Is Java's Date class a unique or unusually bad example? Hardly. The languages and other tools we use are a frustrating blend of components that range from the solidly conceived and superbly implemented to the half-baked and sloppily coded.

Discriminating professionals—programmers and I.S. managers—scrutinize the tools they use and avoid embracing any component based solely on its having come from a respected source. Of course, we can't reinvent everything, and we have to be willing to settle for lower quality in a packaged component than we might be able to develop ourselves. Occasionally, however, we have to reject some standard or vendor's solution because it fails to meet our needs for functionality or maintainability.

The Date class examined—misguided features

There's so much wrong with Java's Date class that it's hard to organize a point-by-point criticism. Here are some of its major shortcomings:

The Date class examined—missing features

With all those things wrong with Date we're even more frustrated by not being able to do the things we need to do to dates without a lot of unnatural and unreadable circumvention:

2009 Addendum:

Sensible programmers were relieved a decade ago to learn that the awful Java 1.0 standard library class described above was to be "deprecated" in Java 1.1 and replaced by an entirely new set of date manipulation facilities. Java's designers and implementors, we thought, were responding to the torrent of complaints. The new facility would surely address most if not all of those complaints.

A later article will examine how that turned out.


Return to technical articles
Return to Java topics
Return to IDI home page

Last Modified, 12 November 2009