# CodeSOD

Published articles for CodeSOD.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## CodeSOD: Extremely One Line

DevFeed: [CodeSOD: Extremely One Line](<https://devfeed.tech/articles/codesod-extremely-one-line-31464.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/extremely-one-line>)

Author: Remy Porter

Published: 2026-09-16T06:30:00Z

Content type: opinion

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [ASP.NET](<https://devfeed.tech/topics/aspnet.md>), [Code](<https://devfeed.tech/topics/code.md>), [Visual Studio](<https://devfeed.tech/topics/visual-studio.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [browser](<https://devfeed.tech/topics/browser.md>), [HTTP](<https://devfeed.tech/topics/http.md>)

Tags: [asp-net](<https://devfeed.tech/tags/asp-net.md>), [browser](<https://devfeed.tech/tags/browser.md>), [cli](<https://devfeed.tech/tags/cli.md>), [code](<https://devfeed.tech/tags/code.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [http](<https://devfeed.tech/tags/http.md>), [studio](<https://devfeed.tech/tags/studio.md>)

### AI overview

This CodeSOD commentary examines an ancient ASP .Net application containing a function written on one line, Safari user-agent detection, and a mysterious "uplevel" value. It criticizes the confusing style and notes that the same pattern appears on multiple pages.

### Source excerpt

Autoformatting your code is a standard thing to do these days. And in those days past, if we're being honest. There's no excuse to not use some kind of autoformatter. Whether you configure your editor to do it or are a weirdo like me who runs a formatter from the CLI as a build step, you've got an easy way to format your code so it looks neat and readable. And some IDEs, like Visual Studio, are pretty insistent about doing this for you. Which makes today's code sample a bit more perplexing. This comes from an ancient ASP .Net application that Austin has the misfortune to work with: protected void Page_PreInit(object sender, EventArgs e){if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)Page.ClientTarget = "uplevel";} protected void Page_Load(object sender, EventArgs e) { Logic(); } Which function is Logic() called from? The fact that I'm asking probably is enough to get you to scroll over. The entire Page_PreInit function is on a single line, followed by the declaration of the Page_Load function. A confusing and annoying choice. The real bonus is that if the browser has "Safari" in its user agent, we set a field to a mysterious "uplevel" value. A mix of user agent sniffing, strings as enums/flags, and wonderfully unclear names. And yes, this particular pattern appears in more than one page in Austin's application. Someone thought this was not just a good idea, but good enough to do over and over again. [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.

## CodeSOD: An Odd Sort

DevFeed: [CodeSOD: An Odd Sort](<https://devfeed.tech/articles/codesod-an-odd-sort-28504.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/an-odd-sort>)

Author: Remy Porter

Published: 2026-09-15T06:30:00Z

Content type: opinion

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [PowerShell](<https://devfeed.tech/topics/powershell.md>), [Script](<https://devfeed.tech/topics/script.md>), [Sorting](<https://devfeed.tech/topics/sorting.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [csv](<https://devfeed.tech/tags/csv.md>), [excel](<https://devfeed.tech/tags/excel.md>), [powershell](<https://devfeed.tech/tags/powershell.md>), [report](<https://devfeed.tech/tags/report.md>), [script](<https://devfeed.tech/tags/script.md>), [sorting](<https://devfeed.tech/tags/sorting.md>)

### AI overview

The article critiques a PowerShell script that queries Active Directory for users and their last logon times. It explains that the script's alphabet-based approach does not correctly sort names, performs unnecessary searches and property loading, and generates a CSV report for Excel despite these inefficiencies.

### Source excerpt

Let's say we wanted to query Active Directory and print out a report of all of our users, and their last logon time. That seems like a pretty normal task for a Powershell script. It'd probably be short and easy to read, at least if it were written by a normal person. Alice sends us one that wasn't. She's already done us a favor, as she writes: "Code cleaned up and indented for the whitespace-missing-impaired." ##################################### # lists accounts and selected attributes alphabetically ##################################### foreach( $letter in "a", "b", "c"......"z") { $strfilter = $letter + "*" $objdomain = New-object System.DirectoryServices.DirectoryEntry $objSearcher = New-object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objdomain $objSearcher.Filter = $strFilter $objSearcher.PropertiesToLoad.Add("name"); $colResults = $objSearcher.FindAll() foreach($result in $colResults) { $name = $result.Properties.Name $searcher = New-Object DirectoryServices.DirectorySearcher([adsi]"") $searcher.filter "(&(objectCategory=User)(sAMAccountName=$name))" $users = searcher.FindAll() foreach($user in $users) { Write-Output $user.properties.item("name") + "," + $user.properties.item("lastLogon") } } } This accomplishes sorting alphabetically by iterating across the alphabet. Which, I suspect, isn't going to actually get them in alphabetical order; it makes sure that albert and alice appear before bob, but doesn't enforce that albert must come before alice. In any case, we iterate across the alphabet, and then create a searcher that finds a*, then b*, etc. We explicitly tell the searcher that the only property we care about is the name field, so that we don't load unnecessary fields, like the ones we want to report on. We then iterate across the list of names, construct a new searcher, and search for the account with the username we fetched. That lets us get all of the fields we need, including the ones we aren't going to use. Now, we sea

## A File Existence Bug Caused by Checking Its Timestamp

DevFeed: [A File Existence Bug Caused by Checking Its Timestamp](<https://devfeed.tech/articles/codesod-i-exist-28510.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/i-exist>)

Author: Remy Porter

Published: 2026-09-14T06:30:00Z

Content type: article

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [bug](<https://devfeed.tech/topics/bug.md>), [Development](<https://devfeed.tech/topics/development.md>), [Windows](<https://devfeed.tech/topics/windows.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [code](<https://devfeed.tech/tags/code.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [development](<https://devfeed.tech/tags/development.md>), [files](<https://devfeed.tech/tags/files.md>), [function](<https://devfeed.tech/tags/function.md>), [time](<https://devfeed.tech/tags/time.md>), [windows](<https://devfeed.tech/tags/windows.md>)

### AI overview

A Pascal system library implements FileExists by checking whether FileAge returns -1. Because FileAge depends on a valid last-write timestamp, files without that timestamp are incorrectly reported as missing. The underlying failure is also not checked for its error code.

### Source excerpt

In addition to using an ancient development environment, with terrible UX, Greta also has the misfortune of working in Pascal. Recently, she was diagnosing a bug. The program was reporting that files didn't exist when they definitely existed. She traced the problem down into the system library. Let's see if you can spot what's wrong: { Delphi / Kylix Cross-Platform Runtime Library } { System Utilities Unit } { } { Copyright (c) 1995-2001 Borland Softwrare Corporation } ... function FileAge(const FileName: string): Integer; {$IFDEF MSWINDOWS} var Handle: THandle; FindData: TWin32FindData; LocalFileTime: TFileTime; begin Handle := FindFirstFile(PChar(FileName), FindData); if Handle <> INVALID_HANDLE_VALUE then begin Windows.FindClose(Handle); if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then begin FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime); if FileTimeToDosDateTime(LocalFileTime, LongRec(Result).Hi, LongRec(Result).Lo) then Exit; end; end; Result := -1; end; {$ENDIF} function FileExists(const FileName: string): Boolean; {$IFDEF MSWINDOWS} begin Result := FileAge(FileName) <> -1; end; {$ENDIF} The first function here is FileAge, which returns the last modified timestamp on a file. Note the use of FileTimeToDosDateTime, which is a Windows API function. It converts LocalFileTime and stores the date part in the first output parameter (LongRec(Result).Hi) and the time part in the second output parameter (LongRec(Result).Lo). Result, in this case, is our return value. If anything goes wrong, we return -1. The FileExists function then, simply calls FileAge. If it doesn't return a -1, there must be a file there. That's an awkward, weird solution to the problem. There has to be a system call that can answer that question more obviously. But it doesn't seem like it should be blowing up- it looks like it should work. But note that FileTimeToDosDateTime also returns a boolean value. If it succeeds, great, but if it fails, it returns false

## CodeSOD: Asynchronous Directories

DevFeed: [CodeSOD: Asynchronous Directories](<https://devfeed.tech/articles/codesod-asynchronous-directories-28505.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/asynchronous-directories>)

Author: Remy Porter

Published: 2026-09-09T06:30:00Z

Content type: article

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [Vala](<https://devfeed.tech/topics/vala.md>), [async/await](<https://devfeed.tech/topics/async-await.md>), [Library](<https://devfeed.tech/topics/library.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [async](<https://devfeed.tech/tags/async.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [await](<https://devfeed.tech/tags/await.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [filesystem](<https://devfeed.tech/tags/filesystem.md>), [writing-code](<https://devfeed.tech/tags/writing-code.md>)

### AI overview

This article examines implementing an asynchronous version of Vala's directory-creation method when the core library provides only a synchronous version. The proposed function walks up the directory tree, then creates missing directories in reverse order, using exceptions for control flow.

### Source excerpt

Eri has a mix of a "true confession" and a "wait, really?" today. The programming language Vala bills itself as a C# like language that compiles into something pretty close to C performance, designed specifically for writing code against Gnome and its associated libraries. One of the C#-isms in brings in is async/await type semantics. You can yield someAsyncFunction(), which returns control to the caller, allowing it to proceed until the yielded function returns an actual value. Because it has asynchronous functions, many library functions for handling I/O are already async. So you can make_directory_async, which yields control so you can keep executing while waiting for the filesystem to make your directory. There are also synchronous versions of those methods. And then there's create_directory_with_parents, which will create a chain of directories for you. That's the synchronous version, and Vala's core library has decided not to provide an asynchronous version of it, which is my "wait, really?" I suspect it's really about the race conditions involved and the risks of things going wrong while doing it asynchronously; all solvable problems, but tricky ones to solve. But it's the problem Eri had, and this is their solution: /// Note: does not throw if target already exists async void create_directory_with_parents_async(File file, Cancellable? cancellable = null) throws Error { var to_create = new File[0]; var? current_target = file; while(current_target != null) { try { yield current_target.make_directory_async(Priority.DEFAULT, cancellable); } catch(IOError.NOT_FOUND e) { to_create += current_target; current_target = current_target.get_parent(); continue; } catch(IOError.EXISTS e) { break; } break; } for (int i = to_create.length - 1; i >= 0; --i) { try { yield to_create[i].make_directory_async(Priority.DEFAULT, cancellable); } catch(IOError.EXISTS e) { // Created by another process } } } If I'm reading this correctly, we start by trying to create the full path to

## An Incorrect Temperature Conversion Lookup Table in Home-Automation Code

DevFeed: [An Incorrect Temperature Conversion Lookup Table in Home-Automation Code](<https://devfeed.tech/articles/codesod-heating-up-28508.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/heating-up>)

Author: Remy Porter

Published: 2026-09-03T06:30:00Z

Content type: opinion

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [floating-point](<https://devfeed.tech/topics/floating-point.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [errors](<https://devfeed.tech/tags/errors.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [open-source](<https://devfeed.tech/tags/open-source.md>)

### AI overview

The article examines home-automation code that uses a floating-point lookup table to convert Celsius to Fahrenheit. It explains that several mappings are incorrect and that using floating-point values as map keys can also cause lookup failures because of rounding errors.

### Source excerpt

A common option for retrofitting heating and cooling into older homes is a mini-split, frequently tied to a heat pump. They're (relatively) cheap to install, energy efficient, and can be added without substantial modifications to the home. They also, annoyingly, are mostly controlled via IR remotes, making them challenging to wire up to home automation or even a household thermostat. People have made solutions, and today's code comes from one of those solutions. Which, I want to stress, this code comes from an open source project for home automation, so it's not the code that's wrong, here. At first I thought it was, and had a moment of, "I'm not going to pick on some hobby project," but then I realised the hobby project points at a deeper issue. // temperature helper these are direct mappings based on the remote float toFahrenheit(float fromCelsius) { // Lookup table for specific mappings const std::map<float, int> lookupTable = { {16.0, 61}, {16.5, 62}, {17.0, 63}, {17.5, 64}, {18.0, 65}, {18.5, 66}, {19.0, 67}, {20.0, 68}, {21.0, 69}, {21.5, 70}, {22.0, 71}, {22.5, 72}, {23.0, 73}, {23.5, 74}, {24.0, 75}, {24.5, 76}, {25.0, 77}, {25.5, 78}, {26.0, 79}, {26.5, 80}, {27.0, 81}, {27.5, 82}, {28.0, 83}, {28.5, 84}, {29.0, 85}, {29.5, 86}, {30.0, 87}, {30.5, 88} }; // Check if the input is in the lookup table auto it = lookupTable.find(fromCelsius); if (it != lookupTable.end()) { return it->second; } // Default conversion and rounding to nearest integer return roundf(fromCelsius * 1.8 + 32.0); } Okay, I am going to pick on their code a little bit; using float as a key in a map is asking for trouble, because rounding errors are going to surprise you. But honestly, failing to find the key you're looking for is better than the opposite, since that actually does the correct thing. Because if you look carefully at the table, you'll see that it's wrong. 18C, for example, should be 64F. Well, 64.4F, but we're rounding to an integer. The choice here is to roughly map every 0.

## CodeSOD: The Big Family

DevFeed: [CodeSOD: The Big Family](<https://devfeed.tech/articles/codesod-the-big-family-28514.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/the-big-family>)

Author: Remy Porter

Published: 2026-08-27T06:30:00Z

Content type: opinion

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [PHP](<https://devfeed.tech/topics/php.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>), [data](<https://devfeed.tech/topics/data.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [Localization (l10n)](<https://devfeed.tech/topics/localization.md>), [formatting](<https://devfeed.tech/topics/formatting.md>), [HTML](<https://devfeed.tech/topics/html.md>), [Parsing](<https://devfeed.tech/topics/parsing.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [code](<https://devfeed.tech/tags/code.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [fetch](<https://devfeed.tech/tags/fetch.md>), [formatting](<https://devfeed.tech/tags/formatting.md>), [html](<https://devfeed.tech/tags/html.md>), [humor](<https://devfeed.tech/tags/humor.md>), [php](<https://devfeed.tech/tags/php.md>), [programming](<https://devfeed.tech/tags/programming.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This commentary examines a large, generalized PHP code sample that builds hierarchical output from a presumed database source. It highlights probable SQL injection risk, unused array keys, dynamic localization fields, extensive number formatting and HTML string manipulation, string-based date-time parsing, and repeated code for child and sibling records.

### Source excerpt

Some time ago, Charles shared with us some awful PHP, aka the most common sort. Today's code sample is maybe a little too big to sum up, but I'll let Charles take a crack at it. It's so bad that even analyzing and laughing at it feels impossible. But it's so bad, I couldn't not share it. I'm the only one handling all the IT-related tasks at my company, and I don't have anyone here to vent or laugh about this kind of thing with. So, I figured, why not share it here? I'm hoping it'll provide at least a little bit of catharsis or some dark humor. To make sure the confidentiality of the codebase was respected, I took the liberty of generalizing it. You might notice some inconsistencies, but that's just me trying to keep things neutral while protecting the original structure and functionality. Apologies if it looks a bit patchy - the goal was to avoid revealing any specific details or sensitive code. The whole block is north of 400 lines, and it's doing a lot. Or well, maybe it's not, as you'll see. Let's star with the outermost layer. $resm_data = $data_source->fetchData("group=" . $item_id); foreach ($resm_data as $key => $value) { // rest of the code here } We fetch data from a data source, presumably a database, passing our condition as a string, which reeks of probable SQL injection, but I don't know what library they're using. I also note they're using the key/value style of array iteration, but never actually check the key. $option_id = $value->option_id; $resm_details = $detail_source->fetch($option_id); if ($resm_details) { $label = $resm_details->{"label$lang"}; $description = $resm_details->{"description$lang"}; $category = $resm_details->category; Nice little bit of "meta" programming to get their localization working, it'll fetch labelen or labelde as needed. Definitely not a horrible, dangerous way to solve that problem. We use that again to get our currency figured out. That lets us do number formatting. So much number formatting code. if ($category == 0)

## A C++ Exception Handler Retries Without Releasing Deadlock Resources

DevFeed: [A C++ Exception Handler Retries Without Releasing Deadlock Resources](<https://devfeed.tech/articles/codesod-lock-em-dead-28511.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/lock-em-dead>)

Author: Remy Porter

Published: 2026-08-26T06:30:00Z

Content type: opinion

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Deadlock](<https://devfeed.tech/topics/deadlock.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code](<https://devfeed.tech/tags/code.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [deadlock](<https://devfeed.tech/tags/deadlock.md>), [exception](<https://devfeed.tech/tags/exception.md>)

### AI overview

The article examines a C++ exception handler that retries after detecting a deadlock. It explains that the retry mechanism appears to jump back to the start of the block without releasing resources, so it can leave the deadlock unresolved and potentially add more deadlocks.

### Source excerpt

Kevin sends us an exception handler from C++. Let's see if we can spot what's going wrong: catch (Exception::Deadlock) { retry; } When we catch a deadlock happening, we retry. That's not a keyword in C++, and looking at how it's used, it has to be some kind of macro, and I suspect that the macro is hiding a goto underneath it. The real problem, though, is that we suspect we're in a deadlock situation. That means this thread is waiting on a resource held by another thread which is waiting for a resource held by this thread. Neither train may continue until the other has passed. So this retry only works if it releases the resource held by this thread (letting the deadlocking thread proceed). But does it? Not according ot Kevin. The code already had a pile of deadlocks in it, so they brought in a highly paid consultant to try and fix them by reordering access and tracing where mutexes were causing issues. This retry just jumps back up to the top of the block, without releasing any resources. It "seems the consultant wanted to add some deadlocks of their own," Kevin says. [Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!