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 2024

Suspicious Contents

by in CodeSOD on

While poring through some VB .Net code, John noticed some odd things in their datamodel. For example, a different process would scan files, and log any "suspicious" files into a database. The program John supported would then report on that data.

One of their classes had a property which looked like this:


Spaced Out Replacement

by in CodeSOD on

You have some text, and need to replace every sequence of spaces with a single space. E.g., My text becomes My text. Now, if you're most of us, you ignore the famous quote and reach straight for regexes.

But Samuel's co-worker isn't most of us.


Totally Valid

by in CodeSOD on

Greg's co-worker really wanted to make sure that a variable was correctly set to true or false. So they did this:

if (isValid == true)
{
	isValid = true;
}
else
{
	isValid = false;
}

Metaception

by in CodeSOD on

Meta-programming- programs which generate programs- is a delightful hobby, but usually shouldn't be used in production code. Usually. I mean, if you're working in LISP, 90% of your program is going to be macros.

But if you're using PHP and JavaScript, there's good odds that someone you work with has decided to combine these two tastes together to create something nobody wants to taste.