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.

Jan 2025

Consultant Conversions

by in CodeSOD on

Janet's company had a glut of work, and thus didn't have the staffing required to do it all. It didn't make sense to hire on any new full-time employees, so they went the route of bringing on a few highly paid consultants, specifically ones who specialized in one specific problem: talking to a piece of hardware purchased from a vendor.

The hardware in question was a scientific which communicated over a serial line. This device provided a lot of data that represented decimal values, but that data was not encoded as an IEEE float. Instead, they used two integers- one for the data, and one representing the number of decimal places.


Halfway to a Date

by in CodeSOD on

Roger took on a contract to fix up a PHP website. During the negotiations, he asked some questions about the design, like, "Is it object-oriented or more procedural?" "No, it's PHP," said the developer.

Which about sums it up, I suppose. Have some date handling code:


Brushing Up

by in CodeSOD on

Keige inherited some code which seems to be part of a drawing application. It can load brush textures from image files- at least, sometimes it can.

static public Brush GetImageBrush(string serviceCode, string imageName, string language)
{
	Brush BorderChannelGroupBrush;
	BitmapImage image = null;

	int point = imageName.LastIndexOf('.');
	string languageImagename = imageName.Substring(0, point) + "-" + language + imageName.Substring(point);

	try
	{
		image = FrameWork.ServicePageImageUrlOnContentServer(serviceCode, languageImagename);
	}
	catch { }

	if (image == null)
	{
		try
		{
			image = FrameWork.ServicePageImageUrlOnContentServer(serviceCode, imageName);
		}
		catch { }
	}

	if (image != null)
	{
		BorderChannelGroupBrush = new ImageBrush(image);
	}
	else
	{
		BorderChannelGroupBrush = Brushes.White;
	}
	return BorderChannelGroupBrush;
}

Irritants Make Perls

by in CodeSOD on

Grün works for a contracting company. It's always been a small shop, but a recent glut of contracts meant that they needed to staff up. Lars, the boss, wanted more staff, but didn't want to increase the amount paid in salaries any more than absolutely necessary, so he found a "clever" solution. He hired college students, part time, and then threw them in the deep end of Perl code, a language some of them had heard of, but none of them had used.

It didn't go great.


Crossly Joined

by in CodeSOD on

Antonio's team hired some very expensive contractors and consultants to help them build a Java based application. These contractors were very demure, very mindful, about how using ORMs could kill performance.

So they implemented a tool that would let them know any time the Hibernate query generator attempted to perform a cross join.


My Identification

by in CodeSOD on

Bejamin's team needed to generate a unique session ID value that can't easily be guessed. The traditional way of doing this would be to generate cryptographically secure random bytes. Most languages, including PHP, have a solution for doing that.

But you could also do this:


Mr Number

by in CodeSOD on

Ted's company hired a contract team to build an application. The budget eventually ran out without a finished application, so the code the contract team had produced was handed off to Ted's team to finish.

This is an example of the Ruby code Ted inherited:


intint

by in CodeSOD on

Ash's company outsourced to an offshore vendor.

This is an example of what they got back: