In terms of coding practice, in what contexts do global constants prefer enumeration and vice versa?
For example, suppose I need a way to express various tile sprites globally. I could do ...
const int TILE_RED = 0; const int TILE_GREEN = 1; const int TILE_BLUE = 2; const int TILE_CENTER = 3; const int TILE_TOP = 4; const int TILE_TOPRIGHT = 5; const int TILE_RIGHT = 6; const int TILE_BOTTOMRIGHT = 7; const int TILE_BOTTOM = 8; const int TILE_BOTTOMLEFT = 9; const int TILE_LEFT = 10; const int TILE_TOPLEFT = 11;
or
enum Tile { TILE_RED, TILE_GREEN, TILE_BLUE, TILE_CENTER, TILE_TOP, TILE_TOPRIGHT TILE_RIGHT, TILE_BOTTOMRIGHT, TILE_BOTTOM, TILE_BOTTOMLEFT, TILE_LEFT, TILE_TOPLEFT };
Obviously, we prefer constants and enums for macros, but what about when it comes to constants and enums? What situations prefer what? I read here that permanent objects pose a small risk of making your program slower, but I would like to hear the thoughts of others.
I used this example, in particular because it is a large set of related objects - pajamas for cats to list.
c ++
trikker
source share