10
Recently, in a project where I have to declare many counts, I came to this doubt. Which is the best option define's
, enum's
or constant variables?
At first I think to use enum
is the best alternative by not polluting the code and working better with the auto-completion of the IDE, but what would be the pros and cons of each approach?
Example of the options I have:
enum Pin
{
PIN_00 = 0x10,
PIN_01 = 0x11,
PIN_02 = 0x12,
// ... muitos outros
};
Or:
#define PIN_00 0x10
#define PIN_01 0x11
#define PIN_02 0x12
// ... outros defines
Or:
namespace Pin
{
const int PIN_00 = 0x10;
const int PIN_01 = 0x11;
const int PIN_02 = 0x12;
// ... Outros declarações
}
Better or worse at all do not exist. What are the pros and cons of each approach, however, is something that can be answered.
– Oralista de Sistemas
I prefer to avoid define and Num because compilers cannot always handle this type of information when displaying values during a debug mode execution.
– lsalamon