CodeSOD: Off the Path Note

CodeSOD: Off the Path

File path separators can be a challenge when writing cross-platform software, and not all programming languages have a straightforward API for handling them. Prior to C++ 17, developers had to use preprocessor magic to handle file path separators, often using the Boost suite of libraries. A common solution was to define a pre-processor constant for the path separator using conditional compilation directives. This approach allowed developers to assemble paths in a way that worked across different file path conventions. However, some developers took a wrong approach, such as appending a path separator and then replacing it with the correct one, which led to duplicated and error-prone code. This incorrect approach was often copy-pasted throughout the codebase, resulting in multiple instances of the same flawed logic. The code was not refactored, despite being used by multiple developers, and it still produced incorrect path separators in some cases. Fortunately, modern Windows is forgiving of incorrect path separators, but this does not excuse the poor coding practice. A better approach would be to define a constant for the path separator and use it consistently throughout the codebase. The use of a self-service release management platform, such as BuildMaster, can help streamline the development process and reduce the likelihood of such errors.