Worst Practices

I'm working on a project where the original authors of the code weren't competent with the tools they chose to use, or the tools that were chosen for them.

The technology involved is BEA Weblogic, Java, Servlets, JSP, HTML, JavaScript, MSSQL.

This is from 1999, and there's no real concept of MVC. Some HTML occurs in the Java instead of the JSP. Part of the business logic is in Java, but more than half happen as SQL stored procedures and functions. Cut-and-pasted blocks of SQL repeat the same task in multiple places with different variables, so if you find a bug in one place, it may be everywhere, and a quick search may not turn it up.

Several bits of that business logic appear to happen by accident. A variable may be returned from a multi-return stored procedure that has been set to a constant at return-time, or may be the value of an uninitialized variable in the SQL that's never used anywhere. Why these weren't set as constants in the Java object, I don't know.

Meanwhile, in using Java, they chose to use as little of the object oriented features as possible. Instead of having an employee, who has a first name, a last name, an id, and so on... they chose to represent groups of employees as rows in two-dimensional arrays with undocumented column names.

Nothing is commented. The primary language of the coders was not English, so the variable names I do have are often misspelled in misleading ways. The variable names in the database are truncated, and often misnamed for what they represent. There is no documentation of what any of the business logic is supposed to do.

The Java itself isn't archaic, it's written in a style I've never seen before. Today, I track back and find out the value of the variable mainPay is always "1", "2", or "3". I stagger across this:
if ( "1".indexOf(mainPay) > -1 )
else if ( "23".indexOf(mainPay) > -1 )


The database isn't normalized, and indeed, isn't planned by someone who understood relational databases. All numbers are stored as strings. Some of the numbers are padded with whitespace, and others aren't, and the distinction is both important and arbitrary. One column that I've found takes user input positive numeric data (1, 2, 3, 4, 5), and stores it as Roman numerals, space-padded to three spaces, but not beyond. However, if one checkbox on screen was selected, the column then stores the character 'Y'.

This is the second ugliest code I've ever worked on, and refactoring doesn't seem to be an option that the management will consider, as we don't have the manpower to do it. I now understand how Cobol was still a problem for Y2K, at least.

My working assumption was that this was done by a group of classic Visual Basic developers who were learning Java as they went, as a VB coder's thought processes would account for most of these problems. The software, given very carefully massaged input, is rock-solid, and I'm astounded every day at how hard these folks must have had to work to get this big of a turd polished to shine on the outside.

1 comment:

Michael Cloppert said...

Thoroughly enjoyable read. I often cringe when I look back at things I did years, and sometimes even months ago, but I'm glad to say I never looked back and saw anything like this.