[rescue] slow java code...an example of why it might be happening
Dave McGuire
mcguire at neurotica.com
Tue Feb 11 11:56:47 CST 2003
I had originally put this in my other message but it seemed that it
needed to be separated.
There's a huge danger of programming in a ridiculously high-level
language like Java when the programmer don't understand the low-level
workings of computers. I suspect that's what's going on here. Take
this problem I dealt with a few weeks ago as an oversimplified example.
A nicely compartmentalized object which, when instantiated, loads some
records from a database based on a parameter passed to a constructor.
The programmer, a guy who started in Java but never learned anything
lower-level, knew this was how to get one of those objects populated
with some data from the database.
Simple, right? Ok, now he needs to generate about 1800 of these
objects...so what does he do? He uses a loop, iterating through the
array of parameters to pass to the constructor. If you're tooling
through your day not thinking too much, and just looking at the object
as a "black box" without thinking of its innards, this is sorta logical
I suppose. It took forever to run.
The correct solution, of course, is to write a new chunk of code
which populates an array of objects (or a similar construct) with ONE
DATABASE QUERY. The guy just didn't understand why it was so slow, and
why his methods were wrong, until I drew it out for him on a piece of
paper...loop iteration, call constructor, do database query, populate
class variables...loop iteration, call constructor...and so forth. He
just didn't understand why this was bad, and more importantly, made no
connection between this and the fact that it was running too slowly!
His brain was trained to build an object, then "close the door" on that
object and completely forget how it works...as long as you remember its
interface, you can just use it anytime you want.
There's a such thing as a programming language whose conceptual level
is TOO HIGH. This is a big problem with inexperienced programmers.
Most of the horribly slow and bloated C++ code that I've looked through
suffers from problems very much like the one I described above, and I
suspect all the commercial farmed-out-to-India bloatware that you guys
are bitching about is like this as well.
-Dave
--
Dave McGuire "I've grown hair again, just
St. Petersburg, FL for the occasion." -Doc Shipley
More information about the rescue
mailing list