In case you haven't gotten your fill of bad code for the week, here are a few "quickies" ...


Let's start out with this single line from Victor Bilyk, who's predecessor liked the long way of writing "true" ...

cbfQry.addParameter( "authenticate_required", new Boolean(true).toString() );

 

Speaking of the long way of doing things, Mike Bare discovered the really long way of setting HOLD_CD to 'N' ...

SELECT CASE WHEN TRANS_ID IS NULL THEN 'N'
            ELSE 'N' END
       INTO HOLD_CD
  FROM GL_OPERATING_TPS
 WHERE OPRTN_ID = v_OPRTN_ID; 

 

Jon Strayer's predecessor thought the following line was a bit ironic, since the mainframe password was not case sensitive at all ...

private static final String MBS_PASSWORD = "f4rth9fe".toUpperCase();

 

Although the next snippet that Sergio submitted really doesn't elicit too much of a "WTF" response, I thought it'd be a nice "farewell" for a decommissioned module written with code almost old enough to drink ...

**   This source code is a part of the legendary Total For-Ex (TFE)
**   trading system, supporting foreign exchange trading activity
**   at Initech Investments.  The system must work on a virtually
**   continuous basis and I, the undersigned programmer, am its
**   benefactor and protector.  As we are truly in the medieval 
**   ages of software development, I am a big fan of simple code.
**   Another artifact unto the Ages....   
**   Custom code - 100% Recyclable, 100% Biodegradable

 

Matt Kane was curious why he couldn't open a new tab, so he did a quick View Source on a Sun web page and learned that they found a way to reinvent the hyperlink ... within the hyperlink ...

<A onclick="location='http://www.sun.com'; return false;" href="#">

 

The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?

#define false 1
#define true 0

 

You can think out your design now (such as separating first and last names into two fields) or deal with it later. Jemm's coworker has no problem doing the latter ... after all, look at how simple it is to split the names in a SELECT query ...

SELECT UserId,
  LastName = 
    REVERSE(SUBSTRING(REVERSE(name),1,LOCATE(' ',TRIM(REVERSE(name))))),
  FirstName = 
    REVERSE(
      SUBSTRING( REVERSE(name),
                 LOCATE(' ',TRIM(REVERSE(name)),
                 LENGTH(name) - LOCATE(' ',TRIM(REVERSE(name)))))
                )
          ...

 

Since I know nothing about Linux/Unix, I showed this next snippet of korn script (from Simmoril)to a Linux guy. He thought it was worth posting and said it was one of the more inventive ways to increment a variable. Anyone care to explain why?

#!/bin/ksh 

[... ommitting unimportant code...] 

export SLEEP_COUNT=`expr $SLEEP_COUNT + 1` 

UPDATE: Jos, who apparently knows more about this than my Linux guy, explains: This is just the classic Bourne shell way of doing math. The Korn shell (and since then the Bourne Again shell) added the "let" statement that let you do math inline, but that was not available in the original shell. We still write many shell scripts with classic code constructs since they're bound to work on each and every Unix system on the planet. I should note that this is why I normally shy away from posting things I don't understand.

I suppose I'll wrap things up with this final snippet of code from Maximillian, who's predecessor seemed to really have some trouble with predicate logic ... and spelling ...

SELECT ard_id, obtain_unx FROM lev_arts
 WHERE NOT (NOT (level_num < @iAquiredLevel) AND NOT (level_num = @iAquiredLevel))