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.

Sep 2010

The Hidden Database

by in CodeSOD on

Back in the days of the first Internet Bubble, Tom received a call from his colleague Steve. They were both contractors, working for the same elite contracting company, and Steve had run into a problem with a Perl script he couldn't figure out. Tom, being a bit more experienced in the arcane art of Perl, was confident he could help out.

The Perl script had started out as a quick hack by an in-house developer, and was little more than a simple CGI script that managed the company's website account database. Apparently, it had run "instantly" many months back, but as of late, it was seeing heavy use and taking a few minutes to run. Worse, it was "occasionally" losing data. And by occasionally, I mean most of the time: it'd typically took an a good three or four attempts to create an account or change a password.


Magic Number 7

by in CodeSOD on

"One of the first things I like to do when working a new contract is dive into the code and work my way around to understand it," Emil wrote, "one line of code that looked like a good start was this."

private ISelecteVariableProperties[] Iselecvariablelst 
    = new ISelecteVariableProperties[ 7 ];

In a Barrel

by in CodeSOD on

Doug's PMO has begrudgingly agreed to move from the Waterfall model to Agile. They've been working through a project plan to make the transition, but unfortunately, it looks like they're still a long way off.


Very Special Strings

by in CodeSOD on

Passwords are a very special type of string. When you type your password into an input box, a • appears instead of the letter you typed. They’ll often contain characters that are really hard to type (like the ~ symbol), and when they get put into a database they’re sometimes encrypted with some sort of “hash”. Plus, passwords can even get too old and expire.

Indeed, strings that are this special need special handling. At least, that’s what Pavel’s colleague must have been thinking when he developed this method and included into the company's common code library.


Dave.cpp

by in CodeSOD on

Noah Finkelstein's coworker Dave was a strange fellow. When he wasn't mumbling to himself in his cubicle, he could be found in deep thought at the snack machine, pondering whether to get animal crackers or Lorna Doones. He'd always get the Lorna Doones, but swear that next time, he'd go for the animal crackers. And everyone was well aware of this, as it was one of the few things the socially-awkward programmer would talk about.

One day, Dave approached Noah with a rather odd question: he wondered if there was a way to un-commit a file in subversion. Puzzled at the request, Noah explained that he could just rollback to a previously committed version, which would effectively un-commit the change. "No, no, no," Dave said in a more-flustered-than-usual tone, "I know that, but I need to get rid of the old version."


Truthful Strings

by in CodeSOD on

Like virtually all modern languages, C# has a built-in Boolean data type. This means that the only values eligible for variables of that data type are true and false, and unfortunately not FILE_NOT_FOUND. In addition, all data types in C# have a ToString() method, which does just that; for Booleans, it returns the appropriate of the two constants System.Boolean.TrueString or System.Boolean.FalseString.

So given that (which, you probably already knew anyway), how would you convert a Boolean to its string representation? If, like Malcolm colleague, you answered the following, give yourself a point!


Accounting for Complexity

by in CodeSOD on

"I was recently assigned to work on a team that maintains a fairly large product," writes Aaron, "at first, I was a bit overwhelmed by the complexity of the architecture. There were countless layers of abstraction, thousands and thousands of classes, and design patterns galore. Since it was such a large project – and my first large project – I figured that the architectural complexity was simply par for the course."

“Then I started looking at the code a little more closely. If I had two words to describe it, they’d be ‘unnecessary complexity.’ And if I had one snippet to describe it, it would be this.”