Article 4647Z Representative Line: Innumerable Enum

Representative Line: Innumerable Enum

by
Remy Porter
from The Daily WTF on (#4647Z)

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 enums, 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.

proget-icon.png [Advertisement] Ensure your software is built only once and then deployed consistently across environments, by packaging your applications and components. Learn how today! TheDailyWtf?d=yIl2AUoC8zAFZM1B4U5-rs
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments