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.

Nov 2009

Pretty Basic Validation

by in CodeSOD on

"For reasons beyond my comprehension," Kristof writes, "one of my coworkers has managed to keep his job after more than eighteen months of messing about. His latest project was to build an import feature in the admin module of our web application. The idea behind the feature was that the administrators could upload a tab-delimited text file containing a list of products, and the application would insert or update the products in the database."

"Of course, the import feature required some pretty basic validation," Kristof continued. "Is it actually a text file? Is it tab delimited? Are the columns correct? And so on."


A Random PHP Script

by in CodeSOD on

Some time ago when Michael was tasked with updating some of code on an old website, one file on the server caught his eye.

Amid an ocean of static HTML files, it turned out that there was exactly one PHP script. Not sure what to expect, he was surprised when he discovered that the script was entirely comprised of vanilla HTML save for one line.


Starring The Admin

by in CodeSOD on

We've all been there before. You spend all this time building a kick-ass, ultra-awesome, super-sweet web application and then you realize you need to build some stupid "administration" module that needs to do the boring, run-of-the-mill things like maintain users, groups, privileges, and so on.

There are several different magnitudes of complexity that can be involved with an administration module, ranging from the full-on set of tables including users, groups, roles, tasks, operations, etc., to a simple IsAdmin column on the users table. Actually, it turns out there's an even simpler way, and that Adam P's predecessor discovered and implemented it for their client's fairly large ecommerce website.


modHmm

by in CodeSOD on

"I was put on a new Microsoft Access project recently," Stuart A writes, "and I've slowly been finding my way around the system as the need arises (read: as bugs are reported). As my eyes drifted over the numerous modules, one stopped me in my tracks. It was a module named 'modHmm'. I guessed the programmer was in a ponderous mood?. So naturally, I had a look inside..."

Option Compare Database
Option Explicit

Global t1qq
Global t2qq
Global t3qq
...

For the Ease of Maintenance

by in CodeSOD on

Ryan Thompson works on a project where all database queries had to go through "stored procedures". Now before you call me out on extraneous quotes or wonder, so what's wrong with stored procedures?, I'm not talking about those kind of stored procedures. I'm talking about "stored procedures" — i.e., the technique developed by Ryan's predecessors for the ease of maintenance.

You see, in Ryan's world, there are hundreds of different procedures, each with a unique identifier such as FNACL0023 or ADUSR0012, all which are stored in a database table named "RawQuery", which, for ease of maintenance, contained the actual SQL queries to be performed. In order to call one of these queries, you'd need to call one of several actual stored procedures — Query0(), Query1(), Query2(), Query4(), Query12(), etc. — depending on the number of "parameters" needed by the query.


The Long Week

by in CodeSOD on

Turns out that I'm The Real WTF, since the Code SOD from earlier today was already posted... last week. Whoops; consequences of posting realllly late at night in a hotel room while at The Business of Software conference I suppose. Anyway, here's one that I'm pretty sure wasn't from last week.


"We recently started using a new CRM system," Gavin Watkinson writes, "and wanted to write some custom functionality for it."


Reading Comprehension

by in CodeSOD on

"After nearly eight years working as a C++ developer," Rik V writes, "a certain coworker of mine was finally laid off. One of his jobs was to run an application that he wrote which would compare two directories and put any files that had changed into a third. This was a semi-frequent task, and one that he needed to devote quite a bit of time to each month. On his departure, the task fell to me."

"The first time I ran the application, I noticed that it was taking an exorbitant amount of time to complete. After five minutes, it barely scratched the surface of the directories, so I took off for lunch and returned later to see it took over forty minutes to complete. Curious as to how a directory comparison could take so long, I peeked at the code.


Slightly OverSQL'd

by in CodeSOD on

"A certain coworker of mine likes to do everything in SQL," Christoffer Hoel writes, "and I mean everything."

"Of course, since our management is non-technical, there's very little any of us can do aside from just toletarting the code. After all, his code runs about the same as ours... and that's all that matters, right?"


The Utility Package

by in CodeSOD on

"It took months of low quality, late delivered code," Scott C writes, "but a certain coder on our team was finally let go."

"I was the lucky one assigned to clean up some of his old code and noticed that several classes of his made reference to a particular utility package. I opened the package and found a single class with 24 methods filled with sad code."