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.

Oct 2015

Leading Development

by in CodeSOD on

H. J. works in a place where best practices are known, but bitterly opposed. You see, they have a lead developer who is more experienced than the rest, and it is his mission to show the others how things should best be done. Some of his finer resume-worthy accomplishments...

  • He removed salted hashes from the database and stores passwords in clear text
  • He swapped out the challenge-response mechanism and replaced it with sending clear text credentials in every request and reply
  • The data-access and object-persistence NHibernate layers were removed and raw db CRUD operations were exposed directly to the internet via these clear-text passwords
  • Set-operations (e.g.: delete-query) were replace with a select and then iteration over the resultant rows - each in its own session (race conditions, transactions: fuggedaboutem)
  • No keys or indices were used in db tables as NHibernate would handle it, even though many tables have more than a million rows
  • Mandatory helper classes log and swallow error and fatal exceptions, leaving them scrolling by on the lead dev's monitor, in case he has time to look at them (this way, the application keeps going and if anyone ever notices something didn't work correctly, they can go scrape the log files)
  • To simplify things, every class and interface had its own namespace and if possible, assembly
  • The build auto-increments the version number of all (changed) assemblies (e.g. just about every class) after each build and then commits it to SVN, pretty much guaranteeing merge issues
  • Created a utility to auto-insert "useful" comments for names of public classes, and name, type and parameters of public methods

This is one class, directly from version control, that deals with Visual Studio solutions and projects. SVN history says it has had precisely one change in it's nearly decade-long life: the addition of the auto-inserted comment:


The Hard Problem

by in CodeSOD on

I’ll warn you to start: this is a date handling CodeSOD, but that’s only a small part of the WTF. You see, there’s an old joke, “There are three hard problems in computer science: naming things and counting things.” This code has a hard time with the first:

       private string ReturnCurrentGMTTime()
        {
            string result = string.Empty;
            DateTime time = DateTime.Now;
            string fs = "yyyy-MM-dd'T'HH:mm:ss";
            result = time.ToString(fs);
            result += "+02:00";
            return result;
        }

A Well Mapped Error

by in CodeSOD on

Marvin’s company had a problem. Their C++ application tended to throw out a lot of error codes. That was actually okay- that application had a lot of possible failure modes that it couldn’t do anything about other than cough up an error and quit.

The problem was that their customers weren’t particularly happy with messages like: Error: QB57, since it told them absolutely nothing. “RTFM” was not an acceptable response, so someone had to add some functionality to turn those cryptic error codes into meaningful messages.


Sort, Then Add, Forever

by in CodeSOD on

Go-live day for the new CabinetWorld redesign was a tense, hurried affair. Developers streamed in at 5:00 AM, hoping to catch wind of early problems before most of the country awoke and started shopping. True to form, the overworked break-room coffee machine gave up the ghost at 5:10, but luckily, at 6:00 the boss brought in doughnuts, and by 6:30 a Starbucks run had been arranged. Everyone huddled in the war room, nervously watching the monitors as the number of concurrent visitors rose steadily. And then ...

1890s Burroughs adding machine


Validate My Feelings of Cleverness

by in CodeSOD on

It’s not uncommon to have a branch in your code along the lines of, if (debugMode) { doSomeLogTypeThingy(); }. Usually, we try and wrap that sort of stuff up and keep it far away from the actual business logic, and the result is a plethora of logging frameworks and diagnostic libraries.

They are, however, consistent about one thing: whether or not debugMode is enabled or not, the actual business logic should behave the same way. They’re designed and intended to be minimally disruptive.


Not So Unique

by in CodeSOD on

When designing a database schema, it's often important to assign a unique identifier to each record. Such surrogate keys almost always make querying for data both simpler and faster, and the overhead of an additional column is usually a cost worth paying. As such, nearly all databases provide some means of generating such identifiers, either in form of sequential numbers, or more fancy UUID schemes.

Snowflake macro photography 1


The Most Pessimistic Search

by in CodeSOD on

Sometimes here at TDWTF, we get code snippets that are immediately obvious in their wrongness. But sometimes, the code only looks mildly inefficient, and it's up to the submitter to let us know how bad it actually is.

Common snail


A Handle on Events

by in CodeSOD on

As developers, we try to write software that will be helpful to our users. Sometimes, we'll do key-by-key examination of what they're typing to do auto-complete. Sometimes, we'll look at a type-field entry to display the relevant subset of subordinate fields to be entered. Sometimes, we'll even try to coalesce error messages so that the user gets one message with a list of mistakes as opposed to one message per mistake.