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.

Jun 2015

We All Float Down Here…

by in CodeSOD on

When Maarten first saw the utility function below, he couldn’t imagine why converting a number from float to double required a string intermediate. Fortunately, whoever wrote this code followed best practices: their comment not only explained what the code is doing, it also explained why.

Pennywise in the sewer


Practical ValiDATEion

by in CodeSOD on

Hampton Court Astrological Clock

Handling dates is difficult.


A Convoluted Time Machine

by in CodeSOD on

Backward Clock - geograph.org.uk - 548623

The web team and the JDE development team rarely see eye-to-eye in Cho's company. Cho, the JDE developer, worked in a world full of Oracle databases and important financial records. Andrew, a web developer, worked in a world full of MS-SQL and sales appointments. So when Andrew asked Cho to put together a job that would remove debt records older than six years so they'd stop showing up in his sales reports, he figured she had things well in hand.


Defensive Programming

by in CodeSOD on

Marino was handed this code. Like all great code, it’s written defensively, protecting itself against nulls, empty strings, and other unexpected values.

I mean, sort of.


Making Progress

by in CodeSOD on

Whenever a program needs to perform a long running process, it’s important that it supplies some sort of progress indicator, so the user knows that it’s running. Sometimes it’s a throbber, a progress bar, an hourglass, or the infamous spinning beachball of death.


Ready for Geocities…

Carol inherited this PHP code, which wants to use a series of dots (“….”)


Required

by in CodeSOD on

Managing namespaces in JavaScript presents its own challenge, since the language’s default behavior is to start slapping things into window . For this reason, people have built a number of libraries and practices to solve this problem.

Jared’s company, for example, uses RequireJS to load dependencies, like the lodash utility-belt library. Sadly for Jared, their new hire proved that all the module-loading libraries in the world don’t solve incompetence.


Sleeping In

by in CodeSOD on

Rebecca inherited some code that’s responsible for gathering statistical data from network interface. It was originally written a decade ago by one of those developers who wanted to make certain their influence was felt long after they left the company.

The code was supposed to write to one of two log files: a “quick log”, with 2-second resolution (but only for the last minute’s data), and a “full log”, with 1-minute resolution.


The Busy Little Boolean

by in CodeSOD on

Booleans! What can you say? They're deceivingly complex features of any language, and only the most proficient among us is capable of using them properly.

Miss M. discovered that one of her cow-orkers found a new way to get the most mileage out of a single boolean variable named count in a single method to see if: