Courageous said:
To me a "magic number" is a hard coded number, directly in a file. These are to be avoided.
So, after reading through the 46 posts, here are my questions/opinions.
C, you say that having hard coded numbers is a bad thing, yet you pose the idea that making static 'named' int variables is a better idea. How, may I ask, is making an int variable that references another int variable any better? If your answer is because it is easy to change, then you should know that the cloc files are also easy to change.
You say that this idea is good because it gives 'meaning' to these 'magic numbers'.
Your example is this: Caster.SendLocalizedMessage( 500237 ); // Target can not be seen.
And you pose the example of the fix to be something like this: Caster.SendLocalizedMessage( TARGET_CANNOT_BE_SEEN );
This is but one example of the strings represented in the cloc files. The strings are not all that short and simple. Some of them are full conversations used for quests. How would you represent a full conversation in a 'named variable'? You couldn't make a variable name that encompases the entire string. And, since you couldn't, the scriptor would still have to look through the cloc files to find exactly what it says.
Even with a 'non-localized'/non 'magic number' database referencing 'magic numbers' with 'named variables', the scriptors would still have to look through to find what entry they want to use.
I've gone through a
lot of code in the core and other distro files and it is probably 90% documented on what the 'magic number' is referencing. If it's not commented, it takes a whole 30 seconds to load the cloc viewer up and enter the number into the search to find what it means.
Courageous said:
If a cliloc code can be changed at any time, the very best strategy one can possibly have is a central location to adjust that in the event the change happens. This is one of the major advantages of a definitions file.
The definitions file already exists. It's called a cloc file and it's provided with each and every install of UO. What if 500237 got changed to 'Target can't be seen'? Would you simply change the reference number in that centralized location and not worry about the variable name? If you're naming the variables for better 'readability' with 'TARGET_CANNOT_BE_SEEN', then you would need to change the variable name to TARGET_CANT_BE_SEEN' to keep true to your rules. You would then need to rename all the refrences to that variable.
Another reason not to do this is the simple matter that doing it would use (waste) resources. You would have 'however many cloc entries there are' ints that would need to be held in memory. It would also have to then do another step to get to the same place. If 'a' goes to 'c', why throw in another step that says 'b = a' so use 'a' when you see 'b'?
Anyway, to sumerize in one word...useless. That's my take on this idea. Although you do bring a good debate
(Notice I claim it as a debate and not an argument) Debates are informed arguments, and you seem to be well enough enformed.