CodeSOD: Numb to Truth
In the ancient times, philosophers asked the hard questions, like What Is Truth? And just when we might thing those questions have been answered, Uli brings us a new twist on an old classic.
"I found this while browsing an ancient C++ codebase," Uli writes.
enum Bool { TRUE, // Value is true FALSE, // Value is false FILE_NOT_FOUND, // Config File Not Found NUM};
The fact that there are comments here is itself shocking and surprising. It's enough to hint that this was a case of convergent evolution with the classic FileNotFound version, especially since this specifies exactly what kind of file is not getting found.
But it's the addition of NUM which adds another twist. Uli explains: "There is a hypothesis that the author wanted to have a nice shortcut for iterating over the values of the enum, like: for (int value = 0; value < NUM, value++)."
If true, that's a terrible choice, but if not true, we're left staring at an even worse and more confounding choice. Regardless, there is nothing left in the code to explain what NUM does, or what it was intended to do. Also, since these are defined as just a standard C++ enum, and not an enum class, it makes NUM a top-level symbol, effectively a global constant, which adds to the annoyance.
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!