Java Leads To Great Libraries

Tim Bray wrote Having Done Java about how writing Java leads to better quality libraries. Needless to say, I disagree. I originally sent this by mail to Tim Bray, but I don’t think that there’s any reason to not publish it here as well.

I’m afraid that I’m going to have to disagree with you on this one. I’ve relatively little experience with Java, but I have been called upon to do some web things. And the standard library makes very, very angry when compared to CPAN[1]. There are a couple of aspects to this:

  • Firstly, everything seems to have been vastly overengineered. Simplicity got thrown out of the window from what I can see. I blogged about one incident (PUTting an URL), but there have been others, frequently involving the bizarre servlets API.
  • Secondly, the strong type system leads to weirdness. This isn’t necessarily Java’s fault, more the people who use it seeing no other way to do things. Again, I’m forced to compare with Perl here. I’m
    thinking in particular of URI.pm, which happily handles https, and http URLs. However, they’re completely different classes in Java. And if you try to feed in one to a method which expects the other, it’s no-go.

Ok, I’ll give in. I’m less moaning about the quality as to the bizarre design which I perceive. But it certainly feels like it should be a factor in any discussion of quality (nebulous as that might be).

1 I’ll admit, however, that there is a huge amount of crap in CPAN too. Anybody remember Meta.pm?

Comments 4

  1. Alastair wrote:

    I agree, although like you say there are language design issues intertwined in the quality of the libraries.

    See also Steve Yegge’s Execution in the Kingdom of Nouns, which gets to the root of what you might perceive as overengineering.

    Posted 29 Apr 2006 at 11:01
  2. Dominic Mitchell wrote:

    I did read “Execution in the kingdom of the nouns” when it first came out. It certainly explains part of it. But it seems to me that there’s still an enourmous amount of Java code that could be a hell of a lot simpler…

    Posted 30 Apr 2006 at 12:28
  3. Tim Bray wrote:

    I tried to reply on your website, but it said “Article points to an item that is no longer available for interaction”. What’s the commenting package written in? 🙂

    What I tried to post:

    Yeah, I really must get a comment system going, but in the interim…

    Funny you should mention LWP. I have spent literally months of my life fighting with LWP. I have never successfully managed to handle requests that either (a) time out or (b) yield endless streams of output. Last time I wrote something serious in Perl to access web data I had to write a little C-language process to do socket API stuff, fork it off, and talk to it through a pipe, otherwise my app hung or broke unpredictably.

    I’d rather do dental work on myself than use LWP again. The Java APIs can be used to deal with all the Web weirdness because I’ve made it work myself.

    Having said that, I agree that a setContent() would be handy.

    And furthermore, there are still lots of problems where I’d rather use perl than Java. But I stand by my point about the APIs.

    Posted 30 Apr 2006 at 23:33
  4. Dominic Mitchell wrote:

    I tried to reply on your website, but it said “Article points to an item that is no longer available for interaction”. What’s the commenting package written in? 🙂

    Ummm, crap. That’s most annoying. It’s typo, written in Ruby, chosen on the grounds that I could fix things and it didn’t involve MySQL. Doesn’t look like those assertions stand up much any more…

    Ahh… I think I know what happened. There was a bug where typo was setting the default action of newly posted articles to “no comments allowed”. That’s been fixed now. My apologies.

    Anyway, thank you for your comments.

    What I tried to post:

    Yeah, I really must get a comment system going, but in the interim…

    Funny you should mention LWP. I have spent literally months of my life fighting with LWP. I have never successfully managed to handle requests that either (a) time out or (b) yield endless streams of output. Last time I wrote something serious in Perl to access web data I had to write a little C-language process to do socket API stuff, fork it off, and talk to it through a pipe, otherwise my app hung or broke unpredictably.

    I’d rather do dental work on myself than use LWP again. The Java APIs can be used to deal with all the Web weirdness because I’ve made it work myself.

    This is interesting. I’ve had generally had no problems with getting LWP to bend over backwards, flip pancakes, etc, etc1.

    OTOH, the few times I’ve used Java to do things, java.net.* has exceedingly gotten in my way. Yes, I’m generally an inexperienced programmer. But I’m experienced enough to be able to know what I want to achieve. At this point, it involves long hours of pain thumbing through “Java in a nutshell” or hitting Ctrl-Space in Eclipse a lot. Usually to no avail, if it involves InputStream or OutputStream.

    Frustrated? Yup. Inexperienced? Yup. Whilst I think that a lot of Java APIs might be great in terms of exposing what’s possible, they do a pretty poor job of making it usable.

    Having said that, I agree that a setContent() would be handy.

    For sure. Shall I just mail my patch to James Gosling? (ha-ha-only-serious)

    And furthermore, there are still lots of problems where I’d rather use perl than Java. But I stand by my point about the APIs.

    Would you mind if I reposted this to my blog on your behalf?

    Thanks,
    -Dom

    1 The problems I have had were:

    • Broken Apache spitting out negative Content-Length headers. LWP didn’t like that at all.
    • changing timeouts on an already connected socket.
    Posted 30 Apr 2006 at 23:37