Skip to main content

CodeSOD: Off the Path

1 week 6 days ago

File path separators are a common pain point when writing cross platform software. Of course, not every programming language has a graceful API for handling that. For example, prior to C++ 17, you had to do some #ifdef preprocessor magic to handle that. Which people usually did (or they'd use the Boost suite of libraries).

Code like this wouldn't be out of place or incorrect:

#if defined(WIN32) || defined(_WIN32) #define PATH_SEPARATOR "\\" #else #define PATH_SEPARATOR "/" #endif

Do I like it? No. But now I've got a pre-processor constant that I can use to assemble my paths in a way that will work across different file path conventions.

Of course, that's the "normal" solution. You could, if you wanted, to it completely wrong. That's what Xian's predecessor did.

#ifdef UNIX filename += "/"; #else filename += "\\"; #endif filename += (*exSeq)[i].path; #ifdef WIN32 ReplaceAll(filename, "/", "\\"); #else ReplaceAll(filename, "\\", "/"); #endif

If we're compiling for unix, append a "/" to the filename. Otherwise, append a "\". Then we append a path out of an array. Then, if we're on Windows, find all the "/" in our filename and replace them with "\". Otherwise, find all the "\" in our filename and replace them with "/".

Instead of defining a constant and using it everywhere you need to construct paths, this code was copy/pasted everywhere you needed to append a path separator onto your string. Well, almost everywhere. Clearly, we don't know that the contents of (*exSeq)[i].path are correct for our target operating system, hence we have to do the ReplaceAll call to sanitize it. Why didn't we sanitize the portion we're appending instead of the whole filename (which presumably is already sanitized?)? A better question: is this running inside of a loop? It looks like it is, based on the [i] array access there.

Multiple developers have copy/pasted this code into multiple places. Not one of them gave a shot at refactoring it. And somehow, there are still code paths that output the wrong path separator sometimes, though at least modern Windows is forgiving about that.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!
Remy Porter

Trump-Shuttered Climate Change Site Now Back Online In Nonprofit Hands

1 week 6 days ago
Donald Trump shuttered the web site Climate.gov in 2025, cutting off public access to climate information from America's National Oceanic and Atmospheric Administration (NOAA). But "former members of the site's team have brought much of it back at a new domain," reports The Register: "Trusted climate information should not disappear when politics change," Climate.us managing director Rebecca Lindsey said of the new platform in a press release. Lindsey, who previously served as the Climate.gov program manager and lead editor, told The Register in an email that she and one of the web developers responsible for the site were the first to be caught up in government purges when DOGE swept through the department in late February 2025... Created in cooperation with sustainability nonprofit accelerator Multiplier, Climate.us aims to be an independent alternative to its old .gov, and many of the former NOAA crew behind the previous website have teamed up for the new initiative to "keep climate information accurate, accessible, scientifically rigorous, and useful for the people who rely on it." Climate.gov, which now redirects to a NOAA page about climate but which hosts none of the data the shuttered site used to contain, was taken offline in July 2025 following a Trump executive order prioritizing "gold standard science...." arguing that prior climate science models relied on worst-case scenarios, which somehow meant the public availability of 15 years of climate data and reporting ought to change... All of the content that was purged from the .gov is now back, along with blogs from experts, climate status reports, maps and data pathways, and national assessments of climate change as well. Lindsey told us that rapidly changing political winds have led her to believe that the government isn't the right place for that mission to continue, and that she would have concerns about returning the site to federal management if a future administration changed its position on climate change... Lindsey said that the Climate.us team will continue with the same mission it had before the Trump administration attempted to quash it: Getting climate science in front of the public in a manner that's understandable so they can make their own decisions about how to respond.

Read more of this story at Slashdot.

EditorDavid