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 2010

SuperRand

by in CodeSOD on

Nearly six years ago, Brian J gave up being a software developer to start a career in law enforcement. He specifically avoided the world of high-tech cyber crime, and wanted to start life anew as your everyday suburban cop. Of course, with a computer engineering degree and several years of IT experience, technology challenges tend to follow him wherever he goes.

For being a suburb, Brian’s department is pretty big and has a wide variety of posts that range from patrol to accident investigation. In addition, certain officers are trained to do certain things, and others have a preference... especially against the few horrible posts – such as manning the speed trap – that just suck the life out of most people for eight hours. As a result, shifts and schedules change from night to night.


Learning Something New

by in CodeSOD on

"When I was tasked to do a few quick changes to the CMCalc 'application', I knew I'd be in for a treat," writes Will, "it's been the bane of all developers on the team: a spreadsheet designed by an end-user who knew too much that was coded by a developer who thought he knew a lot, and maintained over a decade by developers who mostly knew nothing."

"Being that it was VBA, I didn't expect much... yet somehow, I was blown away. It was here that I learned that yes, VBA supports GoTo statements. And line numbers, too. And for whatever reason, those are preferred to a simple If-Else block."


Boolean Truths

by in CodeSOD on

As a bright-eyed and bushy-tailed soon-to-be graduate, Andrew was thrilled to get a job offer before he even graduated. Sure, it involved some new, real-world programming languages that he hadn't worked with, but he was just as confident as his soon-to-be employer that he could pick them right up. And besides, how great would it be to have some solid, real-world technologies like CICS (which probably has something to do with Cisco) and VSAM (Virtual Something Something Something... clearly a cutting-edge technology).

And then the first day hit. Turns out CICS and VSAM were much older than he was, and COBOL was the preferred language of choice. At least I get to work on a mainframe, he told himself. That is, until he learned they were no longer room-sized behemoths staffed by operators wearing cat-eye glasses and bouffant hairdos. It was nothing more than a big ole box called an AS/400.


The Password Reset Façade

by in CodeSOD on

Marius' coworker is a big fan of the façade pattern. Not the software engineering façade, but more the old Wild West town movie set façade. And Although his tenure has long since expired, his elaborate implementations still persist to this day.

Submitted for your approval is this recently uncovered "self-service password change" page. For nearly eighteen months, users had no way of changing passwords on their own; most would simply keep the password they had, while a select few would contact tech support to do it. It took quite a few support tickets to realize that the problem didn't exist between the keyboard and the chair, and it took development just as long to believe that there was a bug. Eventually, Marius was assigned to "fix" it, and he's pretty sure that it took less time to develop the actual code than its façade.


Thourough Username Validation

by in CodeSOD on

Ben recently inherited a massive PHP-based project that makes spaghetti-code look appetizing.

What's so impressive about this system is not the globally misspelled variables or the horribly written constructs, but the downright creative ways in which logic is implemented. Like this unique glued-together mess of PHP/Javascript used for user-name validation:


The Email Tree

by in CodeSOD on

The case for case-sensitivity goes something like this: it's always been that way in this type language and, who knows, maybe someone will find it convenient to have two different variables named LogOnName and LogonName. The case for implicit variable declaration is less clear, but is something like: it's faster to code and coders should just learn to be consistent.

Of course, none of these are very convincing for Murray, who recently stumbled across a project with this.


Extensible XML

by in CodeSOD on

One of the inherent challenges that comes with data is that, once its structure has been defined, it can never be changed. Ever. Data structures are literally chiseled in stone, and the only way to use something different is to rewrite your application from scratch and throw the old application (and any server it touched) in the fires of Mount Doom.

This was actually one of the primary reasons XML was invented. At its core, it’s just one big ole’ human-readable string that’s flexible enough to define any data or specification… even the sacred XML spec itself. Of course, for all of its glory, XML still suffers from a fundamental problem with data: you have to know the data’s structure before you starting working with it. That means analysis, modeling, data dictionaries, and all sorts of other booooooring things that involve not writing code.