Tag Archive for 'Technology'

Infallible APIs

Fellow Atlassian Charles Miller recently wrote an amusing post about methods and constructors in Java that declare a checked exception, but can be called in a way that is required by the specification not to fail. A common example involves string encodings:

try {
    s = new String(byteArray, "UTF-8");
} catch (UnsupportedEncodingException e) {
    throw new Error("UTF-8 is missing??");
}

This code is the result of two conflicting factors. On one hand, since the constructor in question takes an arbitrary character encoding, the case of the encoding being unavailable must be taken into account. On the other hand, 90% of code that calls this constructor will be explicitly invoking a character set that is required to be provided with the Java Runtime Environment, and its absence would be an error serious enough to justify terminating the VM entirely.

The unnecessary exception-handling code is ugly, and obscures the actual intent of the method in which it appears. Charles jokingly proposes adding a “yoda” statement to Java to tell the JVM, “do, or do not; there is no try.”

Continue reading ‘Infallible APIs’

Macworld 2008 Predictions

This year, even more than ever before it seems, everyone has a pet theory on what Steve Jobs will be announcing at tomorrow’s Macworld Expo keynote session. Since I’ve got my own ideas and have been trying to get myself to write on this site more often, I’ll throw in my two cents on the matter. I don’t have much that hasn’t already been said by many others, so I’ll try to keep this interesting.

Continue reading ‘Macworld 2008 Predictions’