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.

Mar 2010

The Incrementing Bit Column

by in CodeSOD on

"I consider myself to be a fairly inquisitive guy," Aaron writes, "I tend to not just dive in and start changing code without understanding the system architecture and a general understanding of the business rules."

"At my most recent job, this quest for knowledge has proven to be just about futile. No one seems to know exactly what the application does, let alone how the system is designed. The schema of the databases all but impossible, and figuring out the logic used in the stored procedures is daunting. Still, when I came across the following bit of T-SQL code, I couldn't help myself..."


The Sorry Server

by in CodeSOD on

There are a lot of things that that you can tell about a codebase by looking only at its comments. Seeing things like “// ask Jim for details” imply overly-complex logic that no human (aside from Jim) could understand, while “increment the counter by 1” shows a certain degree of repetitiveness that probably means lots of copy/paste-style code reuse.

Fortunately for “certain” developers, comments are ignored by compilers and never quite make it past source control repositories. Of course with the Web – and its mix of server- and client-side interpreted languages – what’s intended as an internal comment often becomes plain text that is not rendered or seen by the end user. Well, unless they know where to look.


A Better Date Diff

by in CodeSOD on

It’s a pretty common programming problem: given two dates, determine how many days are between them. Most programmers have the benefit of built-in library code, whether that’s DateTime in .NET, Calendar in Java, and so on. Some – MUMPS programmers, probably – have no choice but to parse and then re-implement the same “30 days hath September…” algorithm. And then of course there are the few who re-implement it anyway, perhaps because they figured that no one else in the history of computing had ever solved that unique problem.

But an even rarer breed are those that, like Paul’s predecessor, who to use built-in code… but from an entirely different platform. Take this method, found in production code, that inputs two dates and a TimeDifference to determine how far apart the dates are. An easy enough concept in C# that’s implemented with a trip to the database.


Should Be Enough

by in CodeSOD on

“It seems every other week,” Samuel writes, “there’s a story about outsourcing gone bad. Maybe we’ve been lucky, but for the past decade or so, we simply couldn’t have survived without our friendly team of offsite developers.”

“You see, I work for a manufacturing company, and our main campus is located a good half-hour away from the outskirts of a suburb of a sparsely populated Midwestern city. Every business in town – from the dry cleaners to the restaurants – is owned or subsidized by the company. Just about every resident works, worked, or will work for the company. ”


Unit Tested

by in CodeSOD on

“I was hired as a ‘best practices consultant’ to help bring a 300-developer company’s development practices into the 21st century,” wrote Ian, “and after six months, I had failed.”

“Our first objective was to introduce automated unit testing. They had all sorts of horribly interconnected code, and the tests would help reduce the fix-here/break-there problems. However, after many, many tutorial sessions with developers, and quite a few long meetings spent trying to convince them of the benefits, no tests emerged. The developers stubbornly held that testers should test code, not them.”


October Road

by in CodeSOD on

“Our codebase is a bit... backwards, to say the least,” writes Aaron Silver, “things that should go up don’t go up or down... instead, they’re painted orange .”

“The postProcessAddress address method is a good example of all of this.”


Injection Proof'd

by in CodeSOD on

“When a ‘customer’ of ours needs custom-developed software to suit their business requirements,” Kelly Adams writes, “they can either ‘buy’ the development services from the IT department, or go to an outside vendor. In the latter case, then we’re supposed to approve that the software meets corporate security guidelines.”

“Most of the time, our ‘approval’ is treated as a recommendation, and we end up having to install the application anyway. But recently, they actually listened to us and told the vendor to fix the ‘blatant SQL-injection vulnerabilities’ that we discovered. A few weeks later, when it came time for our second review, we noticed the following as their ‘fix’.”