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 2016

Every Possible Case

by in CodeSOD on

Road cases 2

From reader Frank comes this delightful Java-flavored head-scratcher:


As The World Ternaries

by in CodeSOD on

Ah, the ternary operator. At their worst they’re a way to obfuscate your code. At their best, they’re a lovely short-hand.

For example, you might use the ternary operator to validate the inputs of a function or handle a flag.


Exceptional Condition

by in CodeSOD on

“This is part of a home-grown transpiler…”, Adam wrote. I could stop there, but this particular transpiler has a… unique way of deciding if it should handle module imports.

Given a file, this Groovy code will check each line of the file to see if it includes an import line, and then return true or false, as appropriate.


It Takes One Function

by in CodeSOD on

Longleat maze

This anonymous submission is the result of our submitter decompiling a Flash application to see how it worked. It’s not often that one thinks to himself, “Wow, some case statements would’ve been a lot better,” but here we are.


unstd::toupper

by in CodeSOD on

C++ is a language with a… checkered past. It’s grown, matured and changed over the decades, and modern C++ looks very little like the C++ of yesteryear. Standard libraries have grown and improved- these days, std feels nearly as big and complicated as parts of Java’s class library.

One useful function is std::toupper. Given a char, it will turn that char into an upper-case version, in a locale-aware fashion. What if you want to turn an entire string to upper-case?