I
Immortal Nephi
I do not find good naming specific types of data. Sometimes, two
variables have same name. I cannot determine which variable name is
to be from either enum or struct. I have to add prefix before
variable name.
The variable name will be EColor and SColor. I should name
ColorTypes in enum and Color in struct.
Option 1 shows prefix Color_ on each color name. Option 2 is
similar, but shows prefix e_. Option 3 may be better. Also, compare
option 4 and option 5 in struct.
Please tell me what you are suggesting how to name variable.
// Option 1
enum Color { // or enum ColorTypes
Color_Black,
Color_Gray,
Color_Write
};
Color color_t = Color_White;
// Option 2
enum Color {
e_Black,
e_Gray,
e_Write
};
Color color_t = e_White;
or
Color color_t = Color::e_White;
// Option 3
enum Color {
Black,
Gray,
Write
};
Color color_t = Color::White;
// Option 4
struct Color {
static const int Black = 0;
static const int Gray = 1;
static const int White = 2;
};
int selColor = Color::Black;
// Option 5
struct Color {
static const int s_Black = 0;
static const int s_Gray = 1;
static const int s_White = 2;
};
int selColor = Color::s_Black;
I want to name my own data types. How do I name keyword in typedef?
I can’t tell which is non-const or const.
typedef unsigned int color_t;
typedef const color_t COLOR_T;
color_t red = 5;
COLOR_T fixedWhite = 10;
I know which typedef I name is non-const and const.
variables have same name. I cannot determine which variable name is
to be from either enum or struct. I have to add prefix before
variable name.
The variable name will be EColor and SColor. I should name
ColorTypes in enum and Color in struct.
Option 1 shows prefix Color_ on each color name. Option 2 is
similar, but shows prefix e_. Option 3 may be better. Also, compare
option 4 and option 5 in struct.
Please tell me what you are suggesting how to name variable.
// Option 1
enum Color { // or enum ColorTypes
Color_Black,
Color_Gray,
Color_Write
};
Color color_t = Color_White;
// Option 2
enum Color {
e_Black,
e_Gray,
e_Write
};
Color color_t = e_White;
or
Color color_t = Color::e_White;
// Option 3
enum Color {
Black,
Gray,
Write
};
Color color_t = Color::White;
// Option 4
struct Color {
static const int Black = 0;
static const int Gray = 1;
static const int White = 2;
};
int selColor = Color::Black;
// Option 5
struct Color {
static const int s_Black = 0;
static const int s_Gray = 1;
static const int s_White = 2;
};
int selColor = Color::s_Black;
I want to name my own data types. How do I name keyword in typedef?
I can’t tell which is non-const or const.
typedef unsigned int color_t;
typedef const color_t COLOR_T;
color_t red = 5;
COLOR_T fixedWhite = 10;
I know which typedef I name is non-const and const.