Recent CodeSOD

Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.

Aug 2012

The Race Case

by in CodeSOD on

"I'm trying to figure out some code and I don't even know where to start with the WTFs!" writes Rachel. "The design has introduced me to a new level of terrible. The naming convention is inconsistent, and the WTFs just keep coming..."

"Here's one of my favorite snips of code. Apparently names are all numeric, and everyone has to be White, Hispanic, Asian, or Indian."


Data? Data data. Data.

by in CodeSOD on

It's natural for a development team to spread the work out. Each member writes small modules, and then the modules are all assembled to implement the business functions the software requires. Sometimes, each developer has a distinct touch and style, and you can tell, just by naming conventions, who was responsible for which block of code. And sometimes, you get blocks like this.

  var srcData = data;
  if (data.data && data.data.data) {
      data = data.data.data;
  } else if (data.data) {
      data = data.data;
  }

  if (!data) {
      return;
  }
Data, data. Data data? Data. Data! Data data data, data data… data.

Square Peg Meets Round Hole

by in CodeSOD on

Have you ever been faced with this scenario? You need to unscrew a Phillips head screw but you only have a similarly sized flat head screwdriver available.

I have and boy was it ever frustrating.


Globally Fiscal Year

by in CodeSOD on

It's easier to teach a non-programmer to program in an object oriented language than it is to teach a Cobol programmer to do the same. That's my experience, and I think Clint would agree. He sent in this VB6 block that he inherited, developed by a self-proclaimed Cobol fanatic. There's not a lot code here, but nearly every line has something… special.


            

There's Always Room to Expand

by in CodeSOD on

"I was going through old e-mail from several years back I ran into this gem," writes Lianna. "This snippet, with data anonymized, comes from the logs of the database as some of the queries that were performed by a particular PHP system:"

update tmp set f76 ='p' where f0=1961520010330;
INSERT INTO tmp (f0,f18,klther) VALUES ('1961720010330','985356431','bestaand');
update tmp set f1 ='' where f0=1961720010330;
update tmp set f2 ='' where f0=1961720010330;
update tmp set f3 ='M' where f0=1961720010330;
update tmp set f4 ='J.' where f0=1961720010330;
update tmp set f5 ='Doe' where f0=1961720010330;
update tmp set f6 ='' where f0=1961720010330;
update tmp set f7 ='Somestreet' where f0=1961720010330;
update tmp set f8 ='123' where f0=1961720010330;
update tmp set f9 ='1001' where f0=1961720010330;
update tmp set f10 ='AA' where f0=1961720010330;
update tmp set f11 ='SOME CITY' where f0=1961720010330;
update tmp set f12 ='0123' where f0=1961720010330;
update tmp set f13 ='456789' where f0=1961720010330;
update tmp set f14 ='[email protected]' where f0=1961720010330;
update tmp set f15 ='1440513' where f0=1961720010330;
update tmp set f16 ='jdoe123' where f0=1961720010330;
update tmp set f29 ='1195073' where f0=1961720010330;
update tmp set f20 ='1001' where f0=1961720010330;
update tmp set f21 ='AA' where f0=1961720010330;
update tmp set f22 ='0123' where f0=1961720010330;
update tmp set f23 ='456789' where f0=1961720010330;
update tmp set f76 ='p' where f0=1961720010330;
update tmp set f48 ='' where f0=1961720010330;
update tmp set f49 ='' where f0=1961720010330;
update tmp set f50 ='' where f0=1961720010330;
update tmp set f51 ='IEG' where f0=1961720010330;
update tmp set f30 ='1287342' where f0=1961720010330;
update tmp set f59 ='AQ' where f0=1961720010330;
update tmp set f61 ='' where f0=1961720010330;
update tmp set f75 ='' where f0=1961720010330;

GUGUID

by in CodeSOD on

GUIDs are unique, but are they unique enough? There is, of course, a slim chance of a collision. Sure, you're more likely to be struck by a meteor and lighting while winning the lottery on a Tuesday during Lent while driving your Ferrari to the diner for pancakes, but it can happen!


Common Functions, not Common Sense

by in CodeSOD on
Ben inherited a an application from a fellow employee on the fast track to retirement. How fast? Well, these are some sample methods in a thousands-of-lines-long class file called, appropriately, "Functions".
	public static string ReturnEmptyStringIfNullElseValue(string value)
		{
			if (value == null)
			{
				return "";
			}
			else
			{
				return value.ToString().Trim();
			}
		}

That isn't the worst, most useless block of code possible. Neither was his method to turn strings into ints.


SQL Splits

by in CodeSOD on

"I should probably start by saying that I am not a SQL expert," Paul wrote. "Sure, I've written my share of SELECT statements, plenty of UPDATE statements, and even a few ALTER statements, but beyond that... nada."

"Fortunately, we do have a SQL guru at work that I can learn from, and thankfully, his code is right there, in the database. Imagine my delight when I uncovered this 2,045-line snippet of SQL Magic that, so far as my non-expert mind can tell, attempts to split a name like 'HARTLEY JR' into two parts."