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.

Apr 2016

Interned Sort

by in CodeSOD on

Caleb scored his first intership at a small, family-owned print-shop. Much to his surprise, the day before he started, their primary web-developer left for a bigger, more lucrative job. His predecssor was an experienced programmer, but came at solving problems in his own unique way. This meant no comments, no functions, no classes, SQL injection vulnerabilities everywere, and cryptic 500-character one-liners stuffed into the value attribute of an input tag.

Caleb spent his first day just trying to get the code running on his dev machine. On the second day, he sat down with a more experienced co-worker to try and understand some of the queries. For example, there was one query that needed to return product details sorted in some meaningful fashion- like by name. Weirdly, though, the page wasn’t sorting them by name, except when it was- no one who used the product search understood the sort order.


See You Last Saturday

by in CodeSOD on

Technocracy-Calendar

One of the more difficult things for beginning programmers to pick up is computer-minded thinking. Sure, if you're reading this, it's probably easy for you to look at a system and plot out how to get the outputs you want in one area out of the information you have in another. For someone who's been programming for years, it's practically second nature. When mentoring interns or teaching beginners, however, it can readily become apparent just how strange this mindset can be to newcomers.


And It's Collated

by in CodeSOD on

As anyone who’s ever written a c-style char * string knows, strings are much more complicated than they look. This is even more true in this modern era of Unicode and character encodings and multilingual applications. How does “ä” compare to “a” or “á”?

John Moore’s company sent some code to a contracting firm. They needed to strip off any diacritics and unusual characters when they were comparing strings, so that “ä” and “å” were treated as the same character when searching- a not uncommon problem. In Java, there’s a special family of classes inheriting from Collator which can be used to solve exactly that problem. Now, most developers aren’t deeply familiar with these, so seeing a contractor that turns in a more “home brewed” approach is hardly surprising.


Parsimony

by in CodeSOD on

Basket of money

When I was but a wee lass, the internet was still a wild, untamed place. Before the advent of walled gardens and minifiers, long before Facebook, you could learn everything you needed to know about web programming using one simple tool: View -> Source.


Tough Cookies

by in CodeSOD on

Raw cookie dough in cookie clumps

Back in 2007, Dimitry worked on a website that received millions of unique visitors.


isAlive

by in CodeSOD on

Why are we here? What is the purpose of life? What does it even mean to be alive?

No, I haven’t been hanging out in coffee shops wearing a beret and discussing philosophy. I’ve instead been puzzling over this code, from Nikolai K.


The Three Second Rule

by in CodeSOD on

The “Five Second Rule” is, of course, a myth. If you drop a food item on the ground, the bacteria living on the ground aren’t going to wait five seconds before moving in. Besides, everything you stuff in your face is already covered with all sorts of bacteria anyway. You have an immune system, you might as well use it.

Adolphus Mannz recently gave his immune system a bit of a workout. In their SalesForce system, they needed a way to determine if a record was being added to the system or updated, and perform some slightly different logic in each case. His fellow developer came up with this rather ugly solution.