It's time for a new series: The Coded Smorgasbord. Inspired by the Pop-up Potpourri, the examples presented here aren't necessarily "bad" code nor do they imply the miserable failure that we're all used to reading here. Like previous "bunch o' code" articles, the examples are more-or-less fun snippets of code like ones that we've all written at one time or another. Enjoy!
Let's start things off with Miki Watts, who 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!!
For those of you with a maturity level greater than "14 years old", this next snippet probably won't be for you. Thankfully, Brian Samson isn't one of those people ..
public class MakeCum { public static void main(String[] args) { ... CLArgParser clap = new CLArgParser(clargs); boolean err = clap.doStdArgs(args); if (err) { System.out.println("Usage: MakeCum "); System.out.println(clap.getStdArgsDescription()); return; } ...}
Ah yes, that class has it all: MakeCum, STD Arguments, and even the Clap makes an appearance! And who would have thought a class that did nothing but "convert a set of binned counts to cumulative counts" could be so fun.
A lot can change in the twelve nanoseconds between the exection of these two instructions. Besides, if something fails in a Try block, everyone knows it can't possibly fail in a Catch block!
foreach (CxNode node in nodeList) { object[] ndArgs = buildArgs(node); try { sb.AppendFormat(node.Output, ndArgs); } catch(Exception) { sb.AppendFormat(node.Output, ndArgs); } }
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 "|"
F.S. noticed that Australian airline JetStar is very careful about ensuring visitors are sent to the proper page ...
if ((version=="NS") || (version=="IE")) { if (version=="NS") /* NS URL */ window.location="/skylights/cgi-bin/skylights.cgi"; else /* IE URL */ window.location="/skylights/cgi-bin/skylights.cgi"; } else /* OTHER URL */ window.location="/skylights/cgi-bin/skylights.cgi";
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)
I suppose we'll wrap things up with Bill Holman, who 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.