CONST vs.#define

When I learned C programming (too many years ago) I used rather a lot of #defines for parameters that may be changed at compile time, or just for readability. Here I see a lot of use of constants for the same purpose. Is there a reason that

const byte LED_Pin = 3;
const byte ON = 1
      digitalWrite(LED_Pin, ON);

is preferable to

#define LED_Pin 3
#define ON 1
      digitalWrite(LED_Pin, ON);


Using constants would force the compiler to place the values (3 and 1 in this example) in memory and refer to those values in the digitalWrite operation, where the use of #define would, with simple compilers and the processors I’ve used in the past, generate the digitalWrite conde with immediate data. Optimization by the compiler, and the details of the AVR-8 architecture may cause the #defines to put the values in memory anyway, but it would give the compiler the choice at any rate.

Noooooooo! In C++ it is really equivalent.

The user of const causes an entry of a new variable in the symbol table and memory is allocated for that identifier. Because it creates an attribute list, the compiler can perform type checking on the use of the variable. A #define is a textual substitution and no memory is allocated for a variable and, hence, no type checking can be performed. The fact that #define's are typeless can be an advantage, as in:

#define ELEMENTS(x) (sizeof(x) / sizeof(x[0])

which returns the number of elements defined for any array regardless of type.

If the Arduino had a true symbolic debugger, I think most programmers would prefer the const version. However, since that's not the case, it probably is a matter of personal choice as much as anything else. Either way, they should be used liberally to get rid of "magic numbers" in a source file.