Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was reading this article: Designing Flags Enumerations @ msdn and it says

Combining flags enumeration values is an intermediate skill that should not be required for developers implementing common scenarios.

I think flags enumeration is awesome - something I learned about during my experience with C.

Why does it seem like this article is cautioning developers away from what I consider to be a useful (and not complex) skill?

share|improve this question

2 Answers 2

up vote 13 down vote accepted

As with many computing concepts, those who understand them don't find them difficult. You're among those people; congratulations!

That doesn't change the fact that bitwise arithmetic seems strange and hard to understand to many people, because it uses a language element (numbers) that they are used to handle in one way (for absolute magnitude) in a very different way (with different meanings for each bit, regardless of their 'value' in the normal number system.)

Yes, there are people to whom this is difficult, and yes, there are a lot of positions that can be filled by people who can't be bothered to learn bit arithmetic. That's what "intermediate" means here.

share|improve this answer

The article says

Consider providing special enumeration values for commonly used combinations of flags.

Of course, it is not really hard to combine different flags using the "|" operator, but providing special enumeration values has the following advantage:

  • easier to read:

    MyEnumeration.MyFlag1 | MyEnumeration.MyFlag2 | MyEnumeration.MyFlag3

    tends to get much more lengthy than

    MyEnumeration.MyCombinedFlags123

  • it makes immediately clear that the specific combination of flags is a legal combination (which may or may not be the case for every other combination)

Nevertheless, I read this sentence from the article not like "don't do this, never ever", only like "make it easier for the common case". There's nothing to say against having no special enum value for a rarely used combination.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.