Sven Sch?le wrote:Hi Uri and all others,
one problem of putting comments into separate files might be the maintenance problem. Separate documentation has to be changed synchronously to changes in the source code; do you think this would really work? Today you only think of Fruit 2.1 but what about future versions?
I think that commenting Fruit2.1 is better than nothing and it is good to understand Fruit2.1 without understanding future versions.
I also think that a lot of files in Fruit2.1 will be unchanged in future version so the comments for them will be relevant also for future versions.
Sven Sch?le wrote:
My experience over years is that commenting directly within the source code is the only acceptable approach while detailled separate documentation (I don't call it "comments" due to its different style of being an external document) is outdated most of its lifetime.
I think that seperate documentation is specifically for Fruit2.1
Assuming that most of the data structure of Fruit will be the same I think that understanding Fruit2.1 can help later to understand also future fruit versions.
Sven Sch?le wrote:That's why I fully agree with Dann in that this can only be done by the author himself, provided he wants to do it. Commenting done by anyone else is a quite dangerous task, as Dann already stated, because it may produce comments looking like an explanation of what the author had in mind when writing a piece of code - which is impossible to tell by someone else than himself.
I disagree that it is impossible to tell.
I can give an example from eval.cpp of fruit about some commenting of king safety evaluation to explain what I mean.
It starts with
if (UseKingAttack)
possible comment is that UseKingAttack=true by default and it was not obvious for me as a reader and I needed to search for UseKingAttack to find it(It was not a long time to do it but I printed all fruit source and if I want to try to understand fruit source by reading when I am not near the computer finding the value of the constant UseKingAttack can take sifgnificant time and even near the computer I do not like to see often
edit->finds in files
Later I see
for (colour = 0; colour < ColourNb; colour++)
I could guess that ColourNb=2 but again I do not want to have misunderstanding so again I search for the string
It appears many times and I need some seconds to see
const int ColourNb = 2 in colour.h
Later I have
if ((mat_info->cflags[colour] & MatKingFlag) != 0)
I understand that it means that the opponent has at least queen and at least 2 pieces but it took me a long time to understand it.
first searching for MatKingFlag gave
const int MatKingFlag = 1 << 3
Later I needed to understand what is
mat_info->cflags[colour]
I figured out that I need to look at material.cpp and find that it has
if (bq >= 1 && bq+br+bb+bn >= 2) cflags[White] |= MatKingFlag;
if (wq >= 1 && wq+wr+wb+wn >= 2) cflags[Black] |= MatKingFlag;
even at this stage it is only a guess that bq>=1 means that black has at least one queen and I need to look at the code to be sure that my guess is right.
only seeing lines like
bq = board->number[BlackQueen12];
remove doubt(I assume that the author did not choose clearly illogical names).
Sven Sch?le wrote:Btw I don't think that Fruit 2.1 source code really needs much more commenting; actually it depends on the level of understanding you want to achieve: understanding the higher-level, functional aspects of some code or understanding lower-level, internal implementation details. For the latter, there may be a need to add a few comments but I am not sure if this is important.
I want to understand both and I do not feel sure of understanding the higher-level without understanding the lower level.
I showed an example why I think that it does need commenting.
Sven Sch?le wrote:
I want to add a personal note on code commenting.
My experience in software development taught me that commenting is essential for "surviving". If you work on different tasks over a certain period of time, or even if different people work on the same task (at the same time or sequentially), you absolutely need excellent code commenting, otherwise you will be lost at some point.
However, most computer chess projects are single person projects, and for many authors it is their main project for a longer period, so things may be different here.
Sven
I think that in the case of Fruit the target of the code is that other people will also work on the code and try to improve it and I think that understanding the code can be productive to improve it.
It was not meant to be only a project of Fabien(otherwise there is no reason for him to release the source code)
I do not plan to try to improve fruit but it does not mean that I do not want to understand it and comments should help people to spend less time in understanding the code(I think that situation when you need a lot of time to understand some code is not encouraging people to try to understand it).