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.

Jul 2010

Strong Web Design

by in CodeSOD on

North Korea is a strange place. From what I've read, it's as close to Hell on Earth as any other place, and their sole economic output appears to be YouTube videos featuring their Mass Games. Oh, and don't even get me started on that whole Dear Leader thing.

But no matter, North Korea is pretty full of itself and, as Rick O'Shay noticed, their website coding is no different: it's really, really strong. See for yourself on the Official webpage of the Democratic People's Republic of Korea (yes, it's a .com):


The 0th Month

by in CodeSOD on

Kevin S. works on websites for a living.

Well, actually, "work" might not be an adequate description considering that part of Kevin's job requires that he is half clarvoyant and half mountain sherpa when it comes to digging through the several huge codebases globbed together abominations of open source, third-party components that he is expected to support.


Testing Fundamentals

by in CodeSOD on

As we learned in Unit Tested, when you require that developers — especially those "certain" developers — write more unit tests, you'll get exactly what you ask for: more unit tests.

Johnny Biggg, whose company recently mandated this, knows this all too well. Although the ratio of testing-to-functional code went up, the quality (or lack thereof) remained about the same. Well, that is, unless you consider how often arrays can fail in JavaScript.


Compare.java

by in CodeSOD on

Tom G. recently joined a team that maintained a fairly large Java client/server application. His first task was fairly simple: prepare for a switch to a different server farm by going through the code to make sure it was portable and wouldn't be affected by a new server, IP address, and so on.

After a few days of browsing through line-after-line of tedious code, Tom found a pretty unique "helper" class: Compare.java. In addition to swathes of unnecessary comparison code, there was equalsAllowNull. Enough was enough, so Tom got up, walked over to his colleague who worked on another project all together, and vented about ridiculousness of Compare.java, and the rest of the code.


Bulletproofed Boolean

by in CodeSOD on

"Some time ago I was checking the business logic that a friend had done for a system." writes Brian, "While I was debugging, I found this awesome piece of code. I understand that application logic should be bulletproofed to handle any kind of data condition passed to it, nulls, double and single quotes, etc., but I felt this to be an example of over-engineering a solution."

public boolean isBooleanFalse(boolean value) {
   boolean response = false;
   if (value == true) {
       response = false;
   } else {
       response = true;
   }
   return response;
}

Database Abnormalization 101

by in CodeSOD on

Working as a DBA in academia, Paul received a notice that a certain newly migrated user schema, specifically the one used by the enrollment tracking system, had swelled to 281 tables and was growing. This had struck Paul as being very strange since the tracking system wasn't all that complicated.

When a student is registering for a class, and want to know if there's room left, they need two pieces of information - the Course ID and the Semester Number.


RePLaCeD

by in CodeSOD on

Varg's colleague had an awfully difficult problem challenge to solve: remove the language parameter ("lang") from a query string.

Well, difficult for Varg's colleague. Though most of us would apply some substring finesse, this particular developer hammered away with a brute force approach.