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.

Sep 2015

MacGyver's XMLHTTPRequest

by in CodeSOD on

In these days of browser standards, it’s easy to forget that once upon a time, simple tasks like an HTTP request from JavaScript were difficult or even impossible, and if you wanted it to work in every browser, you were going to have to write wrappers to try and create a consistent API.

Zeke inherited an application back from those bad old days. It needs to poll a server, and based on the response, it performs an action, but it does this in an “inventive” way.


Sorting Cabinets

by in CodeSOD on

Sorting. It’s a well-studied class of problem, with a number of well-understood solutions. These days, pretty much any time you need to sort a collection, there’s a language-or-framework-provided function that handles it for you. Sure, a Better Idiot™ might try and implement their own sorting algorithm from scratch, but your Regular Idiot™ just has to call .sort- it’s Idiot Proof™, right

Well, David S. found a better idiot.


The Coercive Types

by in CodeSOD on

Loosely typed languages may offer certain advantages in terms of ease of use and flexibility, but they bring another challenge: it’s difficult to know what it is you’re looking at. With no compiler type checking, it’s hard to compare two things, and that becomes extremely problematic when you’re working with languages like, say, JavaScript.

Ruby, in its quest to “make programmers happy”, took a simplistic approach to the Truthy vs. Falsy problem. False is false. Nil is false. Everything else is True. Ruby is often used by web developers, who may be more comfortable in languages like JavaScript and PHP.


Taking Exception

by in CodeSOD on

Like many enterprise organizations, Martin’s workplace decided that they needed to build a collection of .NET assemblies which would be used in every application they built, and would provide important facilities like error handling.

And of course, not only would every application need to use these libraries, every application needed to make use of every component in them, otherwise why have the libraries at all? This meant that every Exception thrown by the application needed to inherit from the BaseException class:


Filter Overflow

by in CodeSOD on

Onboarding was complete, and Denise finally had her PC. Time for her first assignment!

Slow sand rain water filter


Byte me

by in CodeSOD on

Nibbles in a byte

The great thing about Android is the low barrier to entry: thanks to open-source tooling, emulators, and the decision to build on a language often taught in schools, just about anyone can write a simple little app.