August 15th, 2008, 8:31 am
magic numbers The term magic number also refers to the bad programming practice of using numbers directly in source code without explanation. In most cases this makes programs harder to read, understand, and maintain. Although most guides make an exception for the numbers zero and one, it is a good idea to define all other numbers in code as named constants.Because magic numbers are of an arbitrary value, they do not often carry a meaning by themselves; in most cases it is up to the documentation of one's code to specify exactly what the magic number represents. Also, magic numbers are not typesafe, that is, one could erroneously add one to another and arrive at a nonsensical result. Lastly, although highly coincidental, situations arise when numbers may accidentally match magic numbers during comparison operations. It is for these reasons that the use of Enumerated types, or enums, is quickly overtaking the use of magic numbers. Although enums are represented in most languages as an integer (a notable exception is Java)[5], the name of the enum is used rather than the number itself.lots of fun with magic numbers, not droogI am reallly surprised that you could say such a thing.
Last edited by
Cuchulainn on August 14th, 2008, 10:00 pm, edited 1 time in total.