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.

Dec 2020

Classic WTF: 2012

by in CodeSOD on
As we enjoy our holiday today, in this seemingly unending year of 2020, our present to you is a blast from 2012, the year the world was supposed to end. Original --Remy

"Most people spend their New Year's Eve watching the ball drop and celebrating the New Year," writes Jason, "and actually, that's what I planned to do, too. Instead, I found myself debugging our licensing activation system." "Just as I was about to leave the office, I received a torrent of emails with the subject 'License Activation Failed'. One or two every now and then is expected, but dozens and dozens at four o'clock on New Year's Eve... not so good. It took me a moment to realize the significance of 4:00PM, but then it hit me: I'm on Pacific Time, which is UTC -8 hours.

"The error message that was filling up our logs was simply 'INVALID DATE' and for the life of me I couldn't figure out why. Our license code was a 32-bit number that represented the expiration date of the license and the features in the license. 7 of those bits represented the year since 2000, so obviously the date was fine up until 2127. After hours and hours of digging through PL/SQL, Java, JavaScript, Ruby, and some random shell scripts, I found the following.


Classic WTF: Developer Carols

by in CodeSOD on
It's the holiday season, which means over the next few days, we'll be reviewing some of the best of 2020, if anything about 2020 can be considered "the best", and maybe some other surprises. To kick things off, we're going to pull from the faroff year of Christmas 2017, and return to our Developer Carols. That year, we ran them too late to go caroling, and this year, nobody outside of New Zealand should be going caroling, keeping with our tradition of meeting the requirements but delivering absolutely no value. (Original)
Árbol navideño luminoso en Madrid 02

It’s Christmas, and thus technically too late to actually go caroling. Like any good project, we’ve delivered close enough to the deadline to claim success, but late enough to actually be useless for this year!

Still, enjoy some holiday carols specifically written for our IT employees. Feel free to annoy your friends and family for the rest of the day.

Push to Prod (to the tune of Joy To the World)


All About the Details

by in CodeSOD on

Dora's AngularJS team (previously) wanted to have their display be "smart" enough to handle whether or not you were editing a list of "Users" or just one "User", so they implemented a function to turn a plural word into a singular word.

Which, of course, we already know the WTF implementation of it: they just chop off the last letter. So "Potatoes" becomes "Potatoe", "Moose" becomes the noise cows make, and I'm just left saying "oh, gees". But they managed to make it worse than that.


All the Angles

by in CodeSOD on

Web frameworks are a double edged sword. They are, as a rule, bloated, complicated, opinionated and powerful. You can get a lot done, so long as you stick to the framework's "happy path", and while you can wander off and probably make it work, there be dragons. You also run into a lot of developers who, instead of learning the underlying principles, just learn the framework. This means they might not understand broader web development, but can do a lot with Angular.

And then you might have developers who don't understand broader web development or the framework they're using.


Stringing Your Date Along

by in CodeSOD on

One of the best parts of doing software development is that you're always learning something new. Like, for example, I thought I'd seen every iteration on bad date handling code. But today, I learned something new.

Katharine picked up a pile of tickets, all related to errors with date handling. For months, the code had been running just fine, but in November there was an OS upgrade. "Ever since," the users complained, "it's consistently off by a whole month!" This was a bit of a puzzle, as there's nothing in an OS upgrade that should cause date strings to be consistently off by a whole month. Clearly, there must be a bug, but why did it only now start happening? Katharine pulled up the C code, and checked.


Drop into the Deep End

by in CodeSOD on

Would you like to guarantee your project ends up on this site? Antoon's employer has a surefire technique. First, hire a freshly graduated architect with no programming experience. Second, chuck them into a project in a programming language they don't know. Third, give them absolutely no supervision and no guidance or support, and watch what happens.

<?php function copy_tables($table1, $table2, $copy, $size, $link, $action, $testOper) { global $link; //global so we can retrieve it in the fuction "update" global $result; global $timezone; $result[1] = $copy; if ($size = 'EXIST') { $queryz0 = "drop table if exists $table1"; $requestz0 = db_query($queryz0, $link) or error_log("copy_tables *** $table1 : Error in the execution of request z0", db_error() , $action, $testOper) . "\n"; if ($result[1] == "error") { exit; } $queryz1 = "create table $table1 LIKE $table2"; $requestz1 = db_query($queryz1, $link) or error_log("copy_tables *** $table1 : Error in the execution of request z1", db_error() , $action, $testOper) . "\n"; if ($result[1] == "error") { exit; } } elseif ($size = 'NOTEXIST') { $queryz2 = "create table if not exists $table1 LIKE $table2"; $requestz2 = db_query($queryz2, $link) or error_log("copy_tables *** $table1 : Error in the execution of request z2", db_error() , $action, $testOper) . "\n"; if ($result[1] == "error") { exit; } } $queryz3 = "insert $table1 select * from $table2"; $requestz3 = db_query($queryz3, $link) or error_log("copy_tables *** $table1 : Error in the execution of request z3", db_error() , $action, $testOper) . "\n"; if ($result[1] == "error") { exit; } } ?>

Count on Me

by in CodeSOD on

There is no task so simple that a developer can't find a harder, more wasteful, and pointless way to do it. For example, let's say you want to know how many rows are in a data grid object?

Hans found this C# snippet in production a few years ago:


Passive Regressions

by in CodeSOD on

Sometimes, our readers send us a story. Sometimes they send us some bad code. Sometimes, they just need a place to vent their frustrations. Paul T had some frustrations. Paul's team is migrating from .Net to .NetCore, and as one might imagine, that creates a lot of build failures.

Their Team City build environment sometimes doesn't give the most helpful messages:


Going with the Flow

by in CodeSOD on

The power of a good devops team is that you can get fast, reliable, and repeatable deployments. It lays out a foundation for rapid iteration and quick releases. With that in mind, Lakeisha was pretty excited to start a new job working in devops.

She walked in the door, with visions of well architected, scripted flows, robust automated testing, and strict architectural guidelines. About fifteen minutes in, she learn that FISI guided their entire devops workflow. If it worked, it worked.


WWJSD?

by in CodeSOD on

A few months ago, Lee was reviewing a pull request from Eddie. Eddie was a self-appointed "rockstar" developer. Eddie might be a "junior" developer in job title, but they're up on the latest, greatest, bestest practices, and if everyone would just get out of Eddie's way, the software would get so much better.

Which is why the pull request Lee was looking at touched nearly every file. Every change was some variation of this:


A Tight Fitter

by in CodeSOD on

Part of the pitch of Python is that it's a language which values simplicity and ease of use. Whether it lives up to that pitch is its own discussion, but the good news is that if you really want to create really complex code with loads of inheritance and nasty interrelationships, you can.

Today's anonymous submitter started out by verifying some of the math in some extremely math-y analytical code. Previously, they'd had problems where the documentation and the code were subtly different, so it was important that they understood exactly what the code was doing.