It's a particularly busy week for me: on top of a few looming deadlines, I'll be at Business of Software 2008 in Boston. So, I figured it'd be the perfect opportunity to revisit some classics.

This article is a jumble of jumbles, pulled a handful of Coded Smorgasbord-style posts; this was definitely a fun series I'd like to bring back, so please do send in your "more-or-less fun snippets of code like ones that we've all written at one time or another."


Geoff Thompson found a rather obnoxious pattern in his former co-worker's code; all of the "important" methods had a "confirmation" argument that you had to set to true. You know, just in case you accidentally called the method ...

Public Sub ResetCase(Optional ByVal bRestart As Boolean = False)
   If bRestart Then
      objUtils.ResetCase(bRestart)
   End If
End Sub

 

Next up we have a bit of code that Mike Lee came across in some code that he his evil twin had written. I dunno, maybe this isn't so bad. I can see it useful if they ever decide to change the symmetric property of equality ...

if((0 == DblSpread) || (0 == DblSpread))
  SwapGrid.GetCellRange(RowNumber, SwapGrid.Cols[ColDblSpread].Index).Clear(C1.Win.C1FlexGrid.ClearFlags.All);
else
{
  SwapGrid[RowNumber, ColDblSpread] = DblSpread;
  cr = SwapGrid.GetCellRange(RowNumber, SwapGrid.Cols[ColDblSpread].Index);
  cr.Style = StyleBidDblBoldSpread;
}
  

Eric Casto came across some code written by a co-worker who really wanted to make sure his bases were covered ...

if (connected || !connected)
{
  //ED: Snip
}

 

And finally here's the barebones of a 400+ line function that saiti came across called SearchForString. The function is responsible for searching for a string in another string ...

if(searchingAll)
{
  
  //ED: Snip

  if(!AllSearching)
  {
    //ED: Snip
    
    if(!searchAll)
    { 
      //ED: Snip
    }
  }
}

 

Miki Watts came across this line in some API examples provided by an ERP software vendor. J., we're all behind you on this: we hope it's not a bug, too ...

Price = 0e-5; /* J.Palmer 1999-11-15 - I hope it's not a bug */

 

The next example was discovered by T.. For some extra fun, go ahead and count the spaces ...

private final static String twentyspaces = "                         ";

 

Talk about customer service! Josh's company really makes sure that Customer #7742's order date is ... well ... Customer #7742's order date ...

If .Fields("CUST_NUM") = "7742" Then
    dtmOrderPlaced = dtmOrderPlaced
End If

 

Sergei Shelukhin discovered that, for an internal web application at his company, Sundays are officially "every one is an admin" day ...

If WeekDay(Now()) = 1 Or isModuleAdmin = "1" Then
  Response.Write adminLinkHTML
End If

 

The elegant method of integer initialization has survived several check-ins at Steve's company. No one saw fit to remove it, but one developer along the way added a comment explaining it ...

int doctrackId = Convert.ToInt32("0");  //wtf!!

 

I'm sure a lot of you would have mocked Josh's collegue for having a constant named COMMA. Ha! Who's laughing now?

#define COMMA "|"

  

Matt Spicer was in the middle of a VB6 to C# conversion projection and stumbled across this next snippet. He decided to not bring this line of code to the new project ...

lSend = IIf(lSend = True, True, False)

 

Bill Holman used to work on a huge application that is now nearing drinking age (21 years old). It was almost entirely undocumented, it extensively used muli-level and multiple inheritance, and it required a Jedi-level of patience to maintain it. He saved one of the only comments he's ever come across in the system ...

// This instance of OPParcelObj is owned by an instance of 
// OPParcelArray that is associated with an instance of 
// OPCustThread which owns an instance of the parcel 
// processor which is the processor needed to process 
// this parcel.

And that pretty much described the whole system.

 

Most of us test if a number is less than zero to see if it's negative. But not John's colleague ...

If (Mid(CStr(cppObject.GetValue()), 1, 1) = "-") Then ...

 

Here's a bit from Bo Rasmusson ...

I found this in some production code:

int iChkShut; // variables MUST be initialized, not sure why
Funny enough, the parameter iChkShut is used (uninitialized) for comparisment a couple of rows later. 

 

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

 

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 

 

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!