Richard Herring Guest
|
Posted: Fri Jan 27, 2006 10:19 am Post subject: Re: Are MAGIC numbers always bad? |
|
|
In message <43sdtsF1oo3rnU1 (AT) individual (DOT) net>, osmium
<r124c4u102 (AT) comcast (DOT) net> writes
| Quote: | "Richard Herring" writes:
Are MAGIC numbers always bad?
Yes, I think they are always bad.
I am skeptical of most absolute rules like that. They aren't always
bad, but when you can make a reasonable argument against using a magic
number, don't use one. In the end you have to use your best judgment as
a programmer.
I am so glad, since I started working on my Soduku solver, that I repaced
9
with this:
const int number_of_non_zero_digits_in_the_arabic_number_system = 9;
Things are so much clearer now. Thanks for the tip, guys.
Thanks for a neat illustration of two serious programming errors:
premature specialisation and thinking at the wrong level of abstraction.
Hint: some Sudoku variants use 12 numbers or various numbers of letters.
So what's your point? Bingo is different from tic-tac-toe.
|
Yes. What's _your_ point? That's hardly analogous to the difference
between 9x9 and 25x25 Sudoku.
| Quote: | Is the proper
"level of abstraction" games that have something to do with paper? Or what?
|
<sigh> The description at the correct level of abstraction would be, as
my post suggested, the number of tokens to be used, or better still the
numbers describing the grid layout. The fact that the number of tokens
happens to be one less than the base of a certain positional number
system is coincidental.
| Quote: | The properties of the number 9 are built into the thought processes behind
the program.
|
Except that they are not, as witness the variants that have other
numbers:
http://en.wikipedia.org/wiki/Sudoku
That's your premature specialisation.
| Quote: | Is a person who writes a chess program supposed to be keeping
"go" in the back of his mind so he can "enhance" his primitive little
program?
No, but he might want to be aware that there are Oriental chess variants |
where, for example, the pawns start in the third rank.
--
Richard Herring
|
|