Author: Uri Blass
Date: 22:59:19 08/13/03
Go up one level in this thread
On August 14, 2003 at 00:46:26, Steven Edwards wrote:
>On August 13, 2003 at 11:56:38, Uri Blass wrote:
>
>>There are cases when I make changes that are not supposed to change
>>a single global varaible(the changes can be only for speed or only some
>>preperation for another change because new function that I write may be used
>>later in a different way).
>
>Some suggestions:
>
>1. Don't use global variables. A quick fix is to define a struct type that
>contains all of your currently global sate variables along with read, write, and
>compare routines.
Thanks for the suggestion butI do not see how it is a quick fix because
I need to change almost every line of the program
for example I have the following global varaibles in my program
int queens[9][2];
int rooks[10][2];
int bishops[10][2];
int knights[10][2];
int pawns[8][2];
int numqueens[2];
int numrooks[2];
int numbishops[2];
int numknights[2];
int numpawns[2];
I guess that you suggest to change it to the following:
typedef struct
{
int queens[9][2] queens;
int rooks[10][2] rooks;
int bishops[10][2] bishops;
int knights[10][2] knights;
int pawns[8][2] pawns;
int numqueens[2] numqueens;
...
int numpawns[2] numpawns;
}
info;
It means that replacing every queens by info.queens is wrong because it may
also replace numqueens by numinfo.queens
I am also not sure if the computer likes big structs and I am afraid that the
fact that the varaibles are in big struct may force the computer not to do some
optimizations.
>
>2. Consider using C++ instead of C, but don't got locked into any vendor
>specific libraries or classes. With C++, there is ample support for a natural
>and good coding style that eliminates the need for global state information.
>For example. the current CT toolkit source, all in C++, is about 350 Kbytes of
>text with 4,000+ statements, 60+ classes, and zero globals.
I do not know C++ but
I find nothing bad with global varaibles.
I find them more convenient to use instead of thinking exactly
where I use a varaible because if I later decide that I want to use it in
another function there is no problem.
local varaibles are usually varaibles that are used only in a
specific function and have no important meaning after I leave the function.
>
>3. For each aggregate type, consider writing an IsValid() funtion that checks
>for internal consistency. Use the assert facility Ito conditionally trigger
>these checks; you shouldn't care about the resulting slowdown during debugging
>and the assert macros can turn off the code for a production version.
This is probably something that I need to get used to do.
Unfortunately the only chess source code that I learned most of it(tscp)
had not assert in it(or maybe had not enough to make me remember) so I did
not get used to do it.
Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.