M
Monique Y. Mudama
But only if the number or string has the same semantic meaning. If
two numbers appear and happen to be the same value, but one could
change independently of the other, it doesn't make sense to
artificially tie them together.
I know, that should fall under the common sense, but as in other
things, common sense isn't as common as it should be.
I remember discovering the following during a code review:
#define ONE 1
#define TWO 2
#define THREE 3
[...]
...all the way to a hundred or so.
I asked the programmer if he thought that any of these values might
need to change one day (no), or if he could tell me what any of them
meant (only by looking at the code where they were used).
Nobody had ever explained to him the *purpose* of using symbolic
constants, just that it was a bad idea to have the values themselves
directly in the code.
/gordon
Eek.
I had to work with code that had some brilliant lines:
#define PKT_TEN 10
#define PKT_FIFTEEN 15
#define PKT_TWNTYTWO 22
#define PKT_TWENTYTHREE 23
Yes, not only did the previous dev hard-code these numbers, he
actually spelled twenty differently in various packet names.
So then I got to go tracing through the code, trying to figure out
what the heck packet 15 did, anyway.