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.

May 2010

ArticleTypeCodeSOD

by in CodeSOD on

Code generation can be an effective tool for strongly-typing your custom domains if the given domain is constrained to a specific set of values. Acceptable examples would include color names, statuses, and U.S. states, among several others.

In some scenarios it is completely redundant to do so, for example, if you are strongly-typing the alphabet:


The Homegrown CMS

by in CodeSOD on

Several years ago, Mike M’s company decided that they needed to build an in-house Content Management System portal application. Well, actually, the lead developer made the decision… and the recommendation… largely because writing applications are boring. But writing platforms upon which you can write applications… now that’s exciting!

Two years and several failed “proof of concepts” later, and the company had portal driven by a VB6 application with a SQL Server database behind it. If one were to create a list of adjectives to describe this monstrosity, “stable,” “reliable,” and “accurate” would be strikingly absent. However “stillborn” would probably make the top of the list. When Mike took over, the application had 200 forms, one auxiliary code module, and zero classes.


Pipe Dreams

by in CodeSOD on

When digging into a newly inherited codebase, most experienced developers have a preferred way to break the system down into understandable pieces. Most of course start with the documentation, but since there rarely is any, that leaves one of two approaches: back-end to front-end or front-end to back-end. John, a Java and SQL developer, generally likes to start in the database and work his way to the front-end.

Recently, he drew the short straw and was tasked with making a few changes to a legacy Swing application that everyone was afraid to touch. Having never seen the innards of the app, he dove straight to the database and noticed a rather interest querying pattern.


The Power of True

by in CodeSOD on

Most computer scientists could rattle off their powers of 2 just as easily as their powers of 10.

Unfortunately in this instance, Daniel has discovered that possessing such "power"ful knowledge could prove dangerous when it comes to validation:


The Tautology Type

by in CodeSOD on

Consider the tautology: an unnecessary construct that adds no meaning, context, or understanding and may as not exist. In linguistics, it can come in the form of superfluous modifiers such as adequate enough and true fact. In procedural code, it’s simply wrapping code in an “if (true) {…}” block. But in a database table, representing the tautology can be especially tricky.

Fortunately, John’s has solved this problem by inventing a new SQL data type that can be used when a BIT column would allow too much variation in the data. Simply add a BIT column to your table along with a CHECK constraint enforcing that column to be zero.


A Real Tri-State

by in CodeSOD on

Everyone knows that a real Boolean has three states: True, False, and FileNotFound.

This naming conundrum has left many to wonder, if Booleans have three states, what does that make a Tri-State? It's a good question, and one that Peter Bronk has had the unfortunate pleasure of being able to answer. Found deep within the bowels of a big, contrived, and clumsy legacy product, he found a real Tri-State.