[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: Languages etc



On Sep 23, 2005, at 9:31 AM, Robert Thorpe wrote:
used properly. Java programs that are slow are mostly slow because ...
1) Java programmers often program in a way that's prone to be slow, they
generalise things a lot, they write programs that produce a lot of
objects and need a lot of GC.

I have to speak up in agreement here. I'm a procedural programmer (C, mostly) but I've worked on quite a few Java projects over the years. I have narrowed this problem down to programmers whose first exposure was to object-oriented languages like Java or C++. Thinking *exclusively* in object-oriented terms tends to result in unbelievably inefficient code, because computers are inherently procedural things, and pretty, nicely-abstracted object-oriented code gets turned into a most decidedly procedural instruction stream at the time of compilation or execution.


One example of this problem is a commercial database application that I worked on about three years ago, written in Java. The primary developer was an exclusively object-oriented guy. He wrote a method that executed a JDBC query to retrieve a list of names from the database, and another that retrieved the entire record associated with a given name. Then he wrote another routine which used the first method to get the list of names, then iterated over the list calling the second method to get all the records for all names. It took forever, and was a major bottleneck in the system. Of course the right way to do this was with a single query, which is how I rewrote it to solve the performance problem. The guy had NO clue what I was doing.

The world is filled to overflowing with Java and C++ code that does stupid things like this. Isolation and abstraction from hardware is a good thing, but too much of it results in the need for multi-GHz-clocked processors to do the same work we did twenty years ago with 4MHz clock rates.

The point that never seems to enter these peoples' minds is that computer processors are procedural things, not object-oriented things. A little knowledge about how computers actually *work* would result in much, much faster Java and C++ code in the world...but people don't seem to want to go to that much trouble, likely because writing REALLY FAST code doesn't often get one's name mentioned on slashdolt.

            -Dave

--
Dave McGuire "You'll have to be a lot more specific than 'that
Cape Coral, FL girl last night.'" -Ted McFadden