Tom Forsmo said:
Please share. Its always interesting to hear others use of technology,
because one might learn from it.
I made the offer in a mildly mean-spirited kind of
mood. That having passed, I'll try to tell the story
with minimal sarcasm:
The Developer Who Almost Understood Databases
Once upon a time, I inherited a medium-sized Java project,
around 30,000 lines of code. After a few minutes of poking
around, I realized that 9,600 of those lines were in a
single class, the DataMaster. (No names have been changed
to protect anyone, as they started out generic enough.)
Every method in the DataMaster started and finished with the
exact same copy-and-pasted boiler-plate: The method would
open a new Connection to the database, do its own query and
update thing, and close the Connection.
Now, aside from being ridiculously verbose and slow, this
strategy worked. There were some odd bits of data corruption
here and there, but hey, Programming is Hard, and These
Things Happen.
In the course of ripping all this out, enlightenment struck:
Occasionally, one method in the DataMaster would call another.
Unfortunately, as both methods were using the same open/close
boilerplate, they were working in completely different Connections,
and the underlying database's transaction management was shielding
the one from the other's necessary updates.
Ooops.
Go ye and do not likewise.
(Readers are invited to draw their own moral from
this tale, and decide for themselves whether or not
my claim that the developer in question "didn't
understand what a [database] transaction was" was
justified.)