views:

193

answers:

5
+2  Q: 

A matter of style

Would you write something like:

enum XYZ_TYPE {X=1, Y=2, Z=3};

I saw it and the suffix _TYPE confuses me in the enum context. There is a strong prospect that it is because I am not bright.

+1  A: 

XYZ_TYPE is just another name that follows the C++ variable-naming conventions, though I would prefer to use all capital names for preprocessor definitions.

WhirlWind
XYZ_TYPE is not a variable name... It is an enum type name.
Brian R. Bondy
Thanks, I clarified this.
WhirlWind
+1  A: 

There is nothing wrong with that suffix as enums are types of their own, they simply are not type safe.

XYZ_TYPE myXYZ = X;
if(myXYZ == 1) { } //This is what I meant by not strongly typed.

C++0x fixes enums so they are strongly typed though.

Just follow whatever your coding standard says about enum type names. In the end it doesn't matter as long as it is consistent with your coding standard, and it is logically sound.

Brian R. Bondy
That helps a lot Brian. Thanks.
David
+2  A: 

I would not write it just like that, but it's hardly a make-or-break situation. Roll with the punches and save your frustration for things that really deserve it, like for-case loops. :)

Greg D
the for-case loop is priceless! absolute gem!
Big Endian
It's pure power
Brian R. Bondy
+2  A: 

I already have a preferred convention to distinguish types from other identifiers, which is that I use CamelCase with an initial capital for types and lower-case for others. Constants can be all-caps, including enum values.

But "XYZ_TYPE" with any capitalisation is kind of a poor name for an enumeration. I'd use enum Color {RED=1, GREEN=2, BLUE=3};, or enum FuzzyBool {yes=1, no=2, filenotfound=3};, or some such. Not REDGREENBLUE_TYPE.

I think in general if your names are well-chosen then you shouldn't need a _TYPE suffix. If your names aren't well chosen, and to be fair it can be difficult, then maybe you need it to distinguish the type from an object of that type. Maybe. But I prefer to use case.

Steve Jessop
Can't help the caps. This is old code.
David
So the question is, if XYZ_TYPE is the type, then what else is XYZ being used for that means the type couldn't be called XYZ?
Steve Jessop
A: 

We'd just call it an XYZ, making it follow our convention of naming types in CamelCase with a leading capital letter. The enumerated values would be eX, eY, and eZ, following out convention of naming values and variables in CamelCase with a leading lowercase letter, and our convention of all enum values starting with e (constants start with k, and there are no other prefixes in general use. We use a very limited set of Light Side Hungarian.)

As with all conventions, your mileage may vary. But suffixing types with _TYPE seems like a beginner's technique that adds little value for the visual clutter it costs.

Mike DeSimone