08 August 2006

Coding Hell #7

Our company is currently planning to do a major rewrite of the main software product, "porting it to C++" - as they say.


/******************************************************************************\
* Search and branch to hits *
\******************************************************************************/
static void search(void)
{
int lang;

strclr (&KK,sizeof(KK));
MCC (KK.shor,Al220a.shor);
lon = is_full(KK.shor,sizeof (KK.shor));
if (lon
KK.shor[lon] = '%';

if (oexec(cur_rsys_kat))
Oerror (cur_rsys_kat[0]);

cnt_syskat = 0;
fetch_sys_kat();
if(!cnt_syskat)
Shortmsg (" No data for this query found");

erase_list();
return;
}

This search function searches. For what, nobody knows - neither does the function. One would assume that a search function would take at least one argument, and return something - not so our friend here. Despite the fact that nothing is returned, the function still ends in "return" - maybe in the hope that, by returning nothing into the void, the search is not in vain.

Also in there, an other perfect examples for textbook-style programming:

cnt_syskat = 0;
fetch_sys_kat();
if(!cnt_syskat)

"cnt_syskat = fetch_sys_kat();" was obviously considered to be too long, or considered verbose (and thus unoptimized?) programming style. Instead, it uses the global variable cnt_syskat (have fun guessing the type - actually, it is /not/ int), and does nowhere indicate that it is altering global variables.

Or, an other beauty:

Oerror (cur_rsys_kat[0]);

This is - in contrast to what one would assume - NOT a function, but a global macro. A macro which takes a global SQL statement error code, does (probably) something to the passed parameter, and sets an other error code variable - also global, of course.

Now, consider the damage inflicted to your brain after working with thousands and thousands of lines of code, written in this exact same style. This is maintenance hell, and you don't want to be there. Neither do I - friday will be my last day in this abyss.

No comments: