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.

11 Feb 2016


by Erik Gern in CodeSOD on 2016-02-11

In the movie Man of the Year, Robin Williams plays a Jon Stewart-esque comedian who runs for President of the United States. He wins the general election due to a programming glitch in some e-ballot machines deployed nationwide.

In Belgium, as Adrien F. can attest, this very nearly happened.

46 Comments - Last Comment @ 2016-02-12
09 Feb 2016

Keeping Regular

by Remy Porter in CodeSOD on 2016-02-09

Regular expressions can create new problems. Like an industrial drill, they’re extremely powerful- and potentially destructive. They’re expensive, they’re cryptic, but can be extremely concise.

For example, Jessica is reimplementing some C# code written by another developer. This developer was never interested in being concise, and instead favored being “clever”. For example, this developer had an array of strings, and needed to remove any non-word-characters from each string.

85 Comments - Last Comment @ 2016-02-12
04 Feb 2016

Log of String

by Jane Bailey in CodeSOD on 2016-02-04

Zrywka drewna 776

The English language contains words with multiple and often contradictory meanings. A dress, for example, is only one of many items you could put on while dressing yourself. Meanwhile, if you want to wear pants instead, you should avoid pantsing yourself, as that would be counter-productive.

86 Comments - Last Comment @ 00:12
02 Feb 2016

High Performance Memory Allocation

by Remy Porter in CodeSOD on 2016-02-02

Jamie has a co-worker who subscribes to the “malloc is slow” school of thought. Now, for most programs, it’s fine, but Jamie works on a high-performance computing system operating in a massively parallel configuration, so there are portions of their application where that philosophy is completely valid.

In this case, however, the code Jamie’s co-worker wrote is in their message handling layer. There’s really no reason to pool buffers there, as the performance gain is practically non-existent based on the frequency of buffer allocation. That doesn’t change Jamie’s co-worker’s opinion though- malloc is slow.

73 Comments - Last Comment @ 2016-02-09