[geeks] Misuse of Java

Jonathan C. Patschke jp at celestrion.net
Wed Nov 6 13:51:21 CST 2002


On Wed, 6 Nov 2002, Greg A. Woods wrote:

> From the studies I've read (possibly biased studies -- I wouldn't know
> how to tell the difference :-), Java code is inherently slower than
> pretty much every other interpreted or byte-compiled (or object-
> compiled, though I haven't a clue what the latter could really mean)
> code.

It's pretty darned slow without JIT-compiling.  However, since JIT's so
prevalent these days, classic VMs aren't really a consideration for most
applications.

The bias goes both ways, though.  Someone (who -should- have known
better) once told me that if Java didn't have garbage collection, it
would actually be faster than a compiled binary!

> Yup, but don't forget:
>
>     Premature optimization is the root of all evil in programming.
>         -- C.A.R. Hoare

True enough.  But, for a lot of the really bad Java code I've seen,
things like "Don't redraw the whole window every time you insert one of
about 100 widgets during initialization" would fall under
"optimization".  This isn't really optimization, it's more along the
lines of not coding in things that don't need to happen.

I'm also lumping in gereral application design in there.  Some people
(in certain unnamed universities, specifically) try to treat Java
like a functional language, and end up working the garbage collector to
death.  Some people treat it like BASIC and have code jumping all over
the place, making the classloader thrash.

> As far as I've ever been able to tell Java has no valid technical reason
> for being -- never really did, and probably never will.

I'll take that bait.

  1) It's a really clean, if wordy, language.
  2) It has an enormous class library.  When you download J2SE v1.4,
     there is very little that you could want to do that isn't there
     already as a well-documented component.
  3) "Write once, run anywhere" is as much of a reality as it can be.
     There are minor issues in Swing and AWT if you do your layouts
     by-the-pixel, but that's a brain-damaged[1] way to design a GUI,
     anyway.
  4) The package system promotes the best sort of code reuse.

No, it's not a panacea, and yes, you can probably accomplish the same
thing with a huge library of abstraction functions written in C, but
you'd still need to recompile.  It's not the most portable runtime (as
Python would be, probably), nor the fastest (as C would be), nor the
most complete (as PERL would be), but it's a really good compromise.

It's also extremely quick and easy to get something useful up and
running (with support for anything and everything in the class library)
in almost no time at all.  That said, I still do the majority of my
work in C, but that's okay; I like C.


[1] Honestly, I think Microsoft got this more right than anyone.
    Layouts are done in "dialog units" which are derived from the height
    of the system font, so you've got some amount of guarantee that your
    widgets will scale sanely with the resolution of the display.

-- 
Jonathan Patschke
  "Albert Einstein nailed space-time, but the wild thing had him stumped.
   Al, baby, two and two make five-and-a-quarter; that's why people fall
   in love." -- Thomas Dolby, "That's Why People Fall in Love"



More information about the geeks mailing list