Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: what classes all the serious C++ chess programs have?

Author: Daniel Clausen

Date: 07:07:13 08/10/04

Go up one level in this thread


On August 10, 2004 at 09:52:55, Andrew Dados wrote:

>On August 10, 2004 at 08:28:53, Tord Romstad wrote:
>
>>On August 10, 2004 at 05:37:10, Gerd Isenberg wrote:
>>
>>>Generic inline wrapper classes for pieces, moves, hashentries etc. are IMHO nice
>>>to hide implementation and to write "ugly" code once, without any performance
>>>penalty, some examples which same assembly output:
>>>
>>>   if (piece & 0x80) ...
>>>   if (piece & SLIDING_BIT) ...
>>>   if (isSlding(piece) ) ...
>>>   if (piece.isSliding()) ...
>>>or
>>>   if (hashentry.flags & 0x01) ...
>>>   if (hashentry.flags & LOWER_BOUND) ...
>>>   if (hashentry.isLowerBound() ) ...
>>>
>>>I prefere the latter.
>>
>>I understand why you want to avoid the '&' variants, but why is
>>piece.isSliding() better than isSliding(piece), and hashentry.isLowerBound()
>>better than isLowerBound(hashentry)?
>>
>>Tord
>
>
>Actually I prefere: if (hashentry.flags & LOWER_BOUND) ...
>
>Reasons:
>1) less total writing

Well.. I think now you're getting picky. ;) Since "hashentry.isLowerBound()"
uses sslightly less characters, you only have to use it in 10 spots in your
source, and you already saved up enough characters to write the isLowerBound()
method... ;)


>and less possible places to go wrong

Actually I would have used that argument the other way round. With the
isLowerBound() method/function, the logic is implemented only at one place.


>2) faster compile,

That's a point. (although *I* couldn't care less in my projects, especially when
compiling incrementally)


>3) I can rest assured that it is executed as fast as possible and create
>smallest machine code (I am never sure about different compilers treating
>template classes or inlining things or switches or...)

That's a point. For my engine, I really need a good optimizing compiler,
especially with templates. The few tests I did though, indicate that it compiles
it the way I want it. (YMMV, especially with different compilers)


>4) it is easy to read for other people without referring to some other file

Well, sort of... when reading "hashentry.isLowerBound()" I know exactly what the
method/function does. (if coded reasonably, of course) Usually, I don't care
about the concrete implementation of it, but what the code should do.


>For one-time things I will just use plain code...
>-Andrew-

I guess we could debate about all this endlessly. It seems that a lot of it is
just personal taste.

Sargon



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.