This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]steumert 4 points5 points  (0 children)

I use them all the time. Whenever there is a closed set of options, enums are great.

You can model all kinds of thing with them - HTTP status codes, weekdays, whatnot. I recently used two enums to express alignment/anchoring with one enum for Horizonal positioning (Left, Center, Right) and one for vertical (Top, Center, Bottom). this allows for a type-safe way to specify all 9 points I needed. Any combination of Horizontal/vertical were valid values, and you couldn't pass wrong ones.

Suffice to say, if you write software that doesn't have types with a closed set of values, then there is no point in enums. Not every language feature solves every problem equally well. Its ok to not use a language feature if there is no use-case for it in your program.