Intel's Ronler Acres Plant

Silicon Forest
If the type is too small, Ctrl+ is your friend

Friday, August 28, 2009

Nanochess Program & Rules of Precedence

Looking on reddit.com yesterday and I came across "the world's smallest chess program". It sounded kind of intriguing so I downloaded a copy and took a look at it. The author has gone to a good deal of trouble to compact the source code for this program:
  • all the variables are single letters,
  • all extra spaces and newlines have been removed,
  • all unnecessary parentheses have been removed.
All this makes the code virtually unreadable by a person, but the compiler doesn't care. Microsoft Visual C issued 22 warnings, but no errors.

Using a couple of different text editors I expanded it enough that I could start to see some kind of structure to it, but due to the complex expressions and the lack of parentheses it is still incomprehensible. To do any more with it I would have to look up the rules of precedence and then go in and insert the appropriate parentheses.

They made a big deal about rules of precedence when I was studying Computer Science back at the University, but it is one of those arcane subjects that can really screw you up if you happen to make even a single error in the order of evaluation. Computer programs can be complicated enough even in their clearest and simplest expression. Adding assumptions about rules of precedence just makes things that much more complex. I mean it's easy enough to avoid these kind of problems: just use parentheses.

Anyway, I spent a couple of hours fooling around with this program (you can see the results here (update: no you can't, file has been deleted)), and I can see that putting in parentheses to clarify the ridiculously long expressions is going to take several more hours. And then there is the testing that would need to be done to verify that whatever changes I made to the program did not actually change it's behavior. So it's going on the back burner. Maybe I'll look into it again someday, but probably not.

Update September 2016 removed dead link.

No comments: