Stripped of Magic

by in CodeSOD on

A Representative Line is a short snippet that makes you think, "wow, I'd hate to see the rest of the code." A CodeSOD is a longer snippet, which also frequently makes you think, "wow, I'd hate to see the rest of the code," but also is bad in ways that require you to look at the relationship between the lines in the code.

I bring that up, because today's code sample is a long section, but really, it's just a collection of representative lines. Each line in this just makes me die a little on the inside.


The 5-Digit Session Identifier

by in CodeSOD on

Sawyer was talking with a co-worker about how their unique session IDs got created. The concern was that they were only five characters long, which meant there could easily be collisions.

They started by looking at the random number generation function.


Ticking Toks and Expertise

by in Editor's Soapbox on

Knowing the kinds of readers we have here, I strongly suspect that if you drew a Venn diagram of "TDWTF Readers" and "TikTok Users" those circles wouldn't overlap at all. But TikTok is in the news, and because my partner uses TikTok, I'm getting second hand smoke of all of this, I think there's some interesting things to talk about here.

If you've been avoiding this news, good for you. For a long recap, Ars can bring up up to date.. But as a quick recap: TikTok is owned by Bytedance, which is based in China, and subject to Chinese laws. TikTok, like every other social media company, is basically spyware, tracking your behavior to sell your eyeballs to advertisers. Over the past few years, all three branches of the US government have decided that the "Chinese ownership" is the problem here (not so much the spying), and passed a law to ban it unless a US company buys it. The whole thing has turned into an idiotic political football, with Biden saying that his waning days of the Presidency wouldn't enforce the ban anyway, and then the whole thing turns into a Trumpist political football as the incoming President is playing Calvinball and making decrees that he did not (at the time) have any authority to make in the first place.


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.


Secret Horror

by in Error'd on

Casanova Matt swings for the fences. "OKCupid (they don't capitalize the K, but I do, for propriety) must have migrated their match questions through Excel during a recent site revamp. These answers should obviously be 1-2 and 3-4, but maybe I could have 2 with Jan and 4 with Margaret (Mar to friends)."


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;
}

The Whole Thing

by in Representative Line on

David was integrating a new extension into their ecommerce solution, and found this un-representative line:

$this->model_sale_manageorder->exportOrder(substr($selectid,0,strlen($selectid)-1));

Archives