Quoth Seshat
View Post
The "==" actually is "equality" (i.e. 5 == 5), whereas the single = is the "is assigned to", as in "a = 5" (assign the value of 5 to a).
To that end, there are a lot of places and people in the industry that frown on "magic numbers". A constant like that, at least these days, would likely be called a "magic number". Though you could work around it by setting up an enum. So that might look like:
enum HitFailureChance{
Low = 33,
Medium = 66,
High = 90
}
And then in your constant, you could do the following:
private const HIT_FAILURE_PERCENT = HitFailureChance.Low;
Or, you could do as some suggest today, and work with an XML-based config file, and pull the percentages from that. This way, if you want to change the percentages, you can change them in an XML file, and not have to worry (for the most part) about re-compiling your application.
But get this...JavaScript has a "triple equals" (or ===) It does not check for equality based on type coercion.
Sometimes in Javascript, you can get away with things like:
if (5 == "5")
which would return true (I believe).
However, if you did something like the following:
if (5 === "5")
you wouldn't get the type coercion, and the result would be false.
Because 5 the number is different from 5 the character, and since they are different types, they're not equal.
Comment