Not Really an Error'd Error'd

by in Error'd on

Scraping the bottom of the barrel this week, we accepted a couple of submissions that aren't, by any means, Errors. But they're undoubtedly amusing to the likes of those who haunt these pages, and as such, bon appetit.

Diner Dave A. wondered "I wasn't sure if you would really accept this as an Error'd, because it only *looks* like an error, which is why it caught my eye, but it isn't! So, on with the snark: You'd think there'd be Null chance that someone would name a restaurant like this, right? But NO! (Or as YAML would say, Norway!) This really exists -- I haven't been there yet but at the very least its website isn't Null. Maybe two Nulls are like a double negative, making it positively exist?" It doesn't look very filling.


A Big Ol' Log

by in CodeSOD on

We've already picked on bad logging code this week, but we haven't picked on PHP in awhile, so let's look at some bad PHP logging code, from Kris.

        $path = self::getPath();

        if (file_exists($path)) {
            $content = file_get_contents($path);
        } else {
            $content = "";
        }
        $content .= "\n" . date('Y-m-d H:i') . " | " . $message;
        file_put_contents($path, $content);

Truly Strung Out

by in CodeSOD on

Strings in C remain hard. They're complicated- they're complicated because of null termination, they're complicated because of memory management, they're complicated because of the behaviors of const. There's a lot going on in C strings.

But Alice had a simple case: convert a true or false value into the string "true" or "false". Let's see how her co-worker solved this:


Reopening the Log

by in CodeSOD on

The list of things never to write yourself contains some obvious stars: don't write your own date handling, your own encryption, your own authentication/authorization. It's not that no one should write these things, it's that these domains all are very complicated, require a great deal of specialized knowledge, and while easy to get almost correct, they're nearly impossible to get actually correct. If you embark on these tasks, it's because you want to create a product that solves these problems, hopefully not because you've got a terminal case of NIH syndrome.

While it's not as big a star on the list, another domain you probably shouldn't try and solve yourself is logging. Today's anonymous submission isn't the worst home-grown logging I can imagine, but it's got enough bad choices in it to merit some analysis.


An Operating Query

by in CodeSOD on

Sami inherited some C# LINQ code. The actual behavior and purpose of this code is fairly simple. The way the code was written, however, well…

foreach (var operatingMode in ahu.CalculationData.OperatingModes) { operatingModesModel.OperatingModeNames.Add
(operatingModeNumber, operatingMode.OperatingModeName); var 
innerOperatingModeNumber = operatingModeNumber; foreach (var 
property in from partData in operatingMode.PartDatas.Where(p 
=> p.PartGuid == partGuid) let finalOperatingModeNumber = 
innerOperatingModeNumber from property in (from resultProperty 
in this.GetProperties(partData).Where(p => 
FilterAcceptNonSoundAndNonImageProperties(p, updateResult.For
(partData)) && (propertyFilterFunction?.Invoke(partData, p) ?? 
true)).ToList() let measurementUnit = resultProperty.Type.
GetPresentationMeasurementUnit(measurementUnits) let 
measurementUnitTranslationId = measurementUnit?.TextId select 
new OperatingModesModel.OperatingModePropertyModel
(finalOperatingModeNumber, this.TranslationService.
GetTranslator(this.Language.Code).Translate(resultProperty.
Type.NameId), this.PrintoutUtil.GetValueString(resultProperty, 
measurementUnit, this.Language), string.IsNullOrEmpty
(measurementUnitTranslationId) ? "-" : this.TranslationService.
GetTranslator(this.Language.Code).Translate
(measurementUnitTranslationId), resultProperty.Key)) select 
property) { operatingModesModel.OperatingModeProperties.Add
(property); } operatingModeNumber++; }

Twicely Done

by in Error'd on

We received a surfeit of submissions this week. The choices below were selected almost at random, but coincidentally two of them were sent in by regular reader Michael R. to start things off.

Said Michael "Reading CodeSOD on 2023-05-15 made me brush up my knowledge of log. Little did I know that it comes with its own defects. Thank you Google." If you were a mathematician, and wanted to build a wooden table, what else would you use?


Parents In Control

by in CodeSOD on

I've said many unkind things about ASP.Net WebForms in the past. While it leaves a lot to be desired as a web development environment, its event driven approach does map to a lot of folks understanding of software. Click a button, execute code in response. Change a radio button, execute code in response. A simple, easy to understand architecture.

Well, sometimes simple and easy to understand.


intToString

by in CodeSOD on

Krzysztof found themselves staring at a C++ function called intToString. And staring. And then realized that the function makes more sense if you don't look at the name. Let's take a peek:

String intToString(u8* p_param, int p_length) {
	int i;
	int j=0;
	for(i=0; i < p_length; i++)
	{
		j = p_param[i];

		if(j==97 || j==98 || j==99 || j==100 || j==101 || j==102 || j==103 || j==104 ||
			j==105 || j==106 || j==107 || j==108 || j==109 || j==110 || j==111 || j==112 ||
			j==113 || j==114 || j==115 || j==116 || j==117 || j==118 || j==119 || j==120 ||
			j==121 || j==122)
		{
		p_param[i] = j-32;
		}

		if(!isprint((char)p_param[i]))
		p_param[i] = 0;
	}

	string s((char*) p_param);
	return s;
}

Archives