Author: Dann Corbit
Date: 16:28:13 06/07/05
Go up one level in this thread
On June 07, 2005 at 18:17:41, William Hoggarth wrote:
>On June 07, 2005 at 18:00:16, Dann Corbit wrote:
>>More comments are always nice. But they also increase code complexity. There
>>is nothing so bad as a wrong comment too (so if you change the code, the comment
>>must stay in step or you introduce a very serious defect).
>
>I don't see how comments increase code complexity at all.
And yet they do. An added comment is the same as an added line of code.
And {for instance} if you see this:
// decrement the index:
index++;
which is supposed to be correct?
So if you add comments, they absolutely, positively must stay in sync with the
code or they introduce a serious defect.
>They make it easier to
>read. I'm not suggesting adding wrong comments either ;) TSCP did not become so
>popular because the comments get in the way.
TSCP became popular because it is open source and clearly written (assuming a
zillion globals won't cause you problems).
>>>2) Eliminate tricks
>>>
>>>Try to replace things like <<3 and & 15 etc. with a macro that has a more
>>>meaningful name, so people can understand what's going on.
>>
>>Those aren't tricks. They are language elements. Someone who reads a chess
>>program in the C or C++ language should know what they mean.
>
>In one sense you are right, they are not tricks, and yes the reader should know
>about bitwise operations. But compare:
>
>Side^1
Probably you mean:
Side ^= 1;
>switch_sides(Side)
or they are not equivalent, unless they are both the object of an assignment.
>The second is a lot more readable and both will compile to the same code
>(assuming you've set up the macro right).
Both seem equally clear to me.
Never use macros for functions. They are not type safe, and can have evil,
unexpected side effects that are different from a function call because of the
sequence point.
Inline functions are the same speed as macros.
>>I like his naming conventions, but to each his tastes.
>
>Indeed, I did say there were only a few places where it could be improved.
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.