
Least qualified I've cleaned up after? Too many candidates to choose from
I did contract work since the 1980s. We didn't have the terms then, but I was what today would be called a "duct tape programmer", and most of my work was fixing/recovering from/undoing the work of what we call "architecture astronauts" today.
There was the $BIGCORP who bought a $SMALLCORP an inhaled their codebase. The $SMALLCORP had a self-taught BASIC programmer, and a $BIGCORP Pascal coder was ordered to recode the BASIC into Pascal. Unfortunately, it looked like the $BIGCORP programmer understood neither BASIC nor Pascal.
The original BASIC coder had tried, I'll give him that. GW-BASIC ("gee whiz") didn't have data structures or boolean variables, so the BASIC code had added int FALSE=0
and int TRUE=1
at the head of his 8,000 line program, and there were lots of int ValidInput = FALSE;
and if (ValidInput = TRUE) then
constructs. It was actually quite readable, given the limits of the language.
The Pascal code, however was not. The coder had basically just copied over the BASIC into Pascal, compiled it, failed, and cut out what didn't compile. Because Pascal does have boolean variables, int FALSE=0
failed to compile, so the code fixed it to be int NO=0
and int YES=1
. And so all of the boolean logic was done in integers, with if ( booleancondition = YES )
code to get around the pesky problem of not being to use TRUE or FALSE "properly".
The coder also "improved" the basic code by using negative logic. This was "hurts my brain to read" negative logic. Where normal humans would say if ( x or y ) then z();
, he would write if ( not x and not y ) then do nothing; else z();
. He also didn't realize Pascal can do character and string operations, so he did everything in ASCII numerics. With negative logic.
Here's a simple function. Forgive my Pascal syntax, this is from a 40+ year old memory. Also, apologies for the formatting being a mess, el Reg's HTML editor throws away all of the code formatting, no matter what I do.
function validchar( c : char ) : integer;
var
i: integer;
rc: integer;
begin
i := int(c);
rc := NO;
if ( not ( i >= 65 and i <= 90) and not ( i >=97 and i <= 122) ) then
(* do nothing *)
else
rc := YES;
validchar := rc;
end;
For those whose eyes glaze over at that, all it's doing is this:
function validchar( c : char ) : boolean;
type
ValidChars = set of 'A' .. 'Z', 'a' .. 'z';
begin
if ( c in ValidChars )
validchar := true;
else
validchar := false;
end;
And I'm not doing his original code justice, as the if/then/else nesting reached a depth of 40 levels, so trying to pair the else with the if that was 13 screen pages above was a nightmare.
The original BASIC was 8,000 lines. The original Pascal code was over 40,000 lines, and he'd spent five months of the six month project on it, and it didn't work. I ignored the Pascal, took the original BASIC, and wrote a clean Pascal version of it in about a day and a half. It was under 1,200 lines.
Then there was the architect who'd written the company's custom database. His code was already legendary. I once spent two days debugging two lines of a switch statement. The lead coder asked me why I was taking so long, and I showed him the code:
switch(tecsrch(*(TEC**)(id[*f].ttype),id[*f].var,&s,s=3D=3Dstr?(*str?str:="[a-z]"):NULL,func1=3D=3DF02?1:0)){
case -1 :
s=3D(*id[*f].tecfnc)(*(TEC**)(id[*f].ttype),id[*f].var);
if(*s)
...
Thankfully, this was C, not C++. He hadn't started using templates yet. However, he did make extensive use of the SCO Xenix C compiler, which was a problem, as we were trying to convert his code to Linux (Red Hat) gcc. It turns out that gcc is (or was) "far too limited" to handle his code. For example, do you know that if you make a function call in gcc, it only passes the first 128 parameters? Everything after that is not passed on the stack! Do you have any idea how much code that breaks? For most people, the answer would be none, but he had over 800 function calls that used between 140 and 200 parameters.
I was able to migrate some of his utilities to readable, coherent code, but much of it was unintelligable, and there were no requirements as to what it was even supposed to do. Fortunately, he was still with the company, so execs made him clean up the worst of it. He estimated it to take 2-3 weeks; when I left the company, he'd been at it for almost three years, and wasn't even half finished.
The scary thing is that those two examples may be the most vivid, but I can name at least a dozen others.