What are the best names for the first three prime numbers?

I would like to declare an enumeration with the first three prime numbers. For example


What would be the best names for these enumerators? Or the names I used are good enough?
Last edited on
Or another variant


What is the better?

That's your question? There's no 'best name'. It's a matter of taste.

I'd name them like so:
namespace Prime
  enum EType { First = 2, Second = 3, Third = 5 };
I can't help thinking that the words THE, PRIME, and NUMBER are redundant as all them have this. So I like coder777's example.

Possibly better using a typed enum:

#include <cstdint>
enum class Prime : std::int8_t { First = 2, Second = 3, Second = 5 };

Hope all is well at your end 8+) - Cheers
Why stop at the first three, why not name them all ;-)
ajh32 wrote:
why not name them all

That would anger Euclid
I do think that all-caps is increasingly out of fashion with enums these days; it was only ever a hang over from #defined constant values. (Though Google does, I see, allow both kEnumName and ENUM_NAME in their coding style guidelines).

Also, I do prefer to name enums as a rule. Where some people would anonymous enums to define constants, I generally use static consts.

And I have come across the following form quite a bit:

enum Prime { primeFirst = 2, primeSecond = 3, primeThird = 5 };

or even

enum EPrime { ePrimeFirst = 2, ePrimeSecond = 3, ePrimeThird = 5 };

(Giving every enum its own namespace would clutter up the output generated by Doxygen; using this approach means the namespace list provided by Doxygen will be just the big, meaningful namespaces. I have yet to try Docygen with new-style enum classes.)

Last edited on
How about enum {PRIME1 = 2; PRIME2 = 3; PRIME3 = 5; }; ?
I would simply refer to them as P1 P2 and P3

The reason is when you look at math equations, they use (P+4)
Where P = Prime.

So you could use P[i] where i is a list of primes numbers.


I do think that all-caps is increasingly out of fashion with enums these days; it was only ever a hang over from #defined constant values.

I use all capital letters that underline that they are fixed constant. Names with non-capital letters have some meaning of variability.

So there is no problem whether these names are defined through an enum or are macro definitions.

I have an opinion that the best names will be FIRST_PRIME_NUMBER, SECOND_PRIME_NUMBER and THIRD_PRIME_NUMBER.
To use simply First, Second and Third or P1, P2 and P3 or PRIME1, PRIME2 and PRIME3 is not a good idea.

Thanks to all.
Last edited on
Topic archived. No new replies allowed.