(written while working at a large pharmaceutical company)
I’ve been “working” most of the day, but it’s what I call “obsession work” – like obsessively scratching an itch. I doubt my boss understands why I work so hard on things like this.
I was handed some legacy Perl stuff to patch up. When I say legacy, I mean perl4, and when I say patch up – I have never, ever seen code this bad. I mean – I’ve seen lots of code, and I’ve seen lots of poorly written code with lots of bugs, but this is in a class of its own – because, you see, it works. It’s like Wolfgang Pauli said – “This isn’t right. This isn’t even WRONG.” The guy who wrote this stuff essentially takes several thousand lines to do what I can do in fifty, because he reinvents everything in the process.
Here’s a representative sample; bear in mind that he does many things just like this, all just as horrible.
He doesn’t know about arrays. He doesn’t know about arrays!
Instead, he has two scalar (string) variables:
concatentation of all the data values, and
concatenated list of offsets into
mydata. For example, take this array:
@apples = ("rome","mcintosh","granny smith","delicious")
He instead does this:
$apples = "romemcintoshgranny smithdelicious" $apples_offsets = "000004012024"
Get it? Three digits each. The offset of
delicious 024. He knows that the offsets of
$apples_offsets variable itself (which, after all, is
itself a pseudoarray) are consecutive multiples of 3, so he doesn’t
need a meta-meta-meta-meta-etc-offset.
The mind boggles.
I see this code and I can’t help but fix it. It’s like … here’s this immensely ugly thing, and I can tear it all down and make it beautiful. Never mind that the end product is rather humdrum – a very simple records entry utility – I’ll sit here for hours studying his code, looking for all the idiosyncrasies that other systems now depend on (once others have coded a workaround to a bug, the removal of the bug would be a bug…), and in the end replacing his 12,000 lines of code with around 200.