Ah, the enumerated type. At its core, it's really just a compile-time check to ensure that this constant containing 1
isn't getting confused with this other constant, also containing 1
.
We usually ignore the actual numbers in our enum
s, though not always. Perhaps, though, we should just pay more attention to them in general, that way we don't end up with code like Andrew found.
public enum AddressPointerTable
{
Default,
Two
}
This is C#, but the behavior would be more or less the same in any C-like language. The first entry in the enum
has the value 0. The second has the value 1.
So Two == 1
.
Now, the real problem with this code is that these are just terrible names, all the way around, and it's impossible to even guess what they might mean out of context. But the part that had Andrew and his co-workers laughing was that two is one.