Nonsense. Checking for conditions that will and can never occur is a pure waste of time. The total benefit integrated over eternity will be exactly zero.sje wrote:One must be careful to avoid the unhealthy desire for short term gains which result in high long term costs. Compared to a slower but more sure approach, a rushed project will always cost more and produce results of lower quality.
Problem with bitboard knight attack generator
Moderators: hgm, Rebel, chrisw
-
- Posts: 27894
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: CookieCat's board decoder
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: CookieCat's board decoder
Have you ever been involved in real commercial software development projects?hgm wrote:Nonsense. Checking for conditions that will and can never occur is a pure waste of time. The total benefit integrated over eternity will be exactly zero.sje wrote:One must be careful to avoid the unhealthy desire for short term gains which result in high long term costs. Compared to a slower but more sure approach, a rushed project will always cost more and produce results of lower quality.
And how can you know which conditions "will and can never occur"?
Sven
-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: CookieCat's board decoder
I actually think the only problem with the setFen issue was the question of where is the best place to error check the fen ?
if you assume a function has a working input and output then you don't call the function until you have called IsFenValid() for example.
if you assume a function has a working input and output then you don't call the function until you have called IsFenValid() for example.
Last edited by Dave_N on Wed Dec 28, 2011 1:28 pm, edited 2 times in total.
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Problem with bitboard knight attack generator
From my experience it is simply the wrong view to say that "fixing some error checking is a waste of time". It is always cheaper to include error checking immediately when designing the algorithm. If you add it later then you add much more testing effort, and there is a high risk that you introduce new errors by changing the algorithm (or its implementation) to include error checking. Better include it right from the beginning.Dave_N wrote:I think it depends on the project, if you have X amount of time until alpha (example: your software needs to have a working demo and you can use a laptop / video to show your investors) then why waste time fixing some error checking that is perfectly straightforward when you don't need a playable demo until beta testing, and even then you can wait for someone to complain about the bug because the official release doesn't happen until after a month of waiting for bug reports.sje wrote:This is the only good way of doing things. Long, long ago in school I learned the technique as "defensive programming", but by any name it's the best practice.Sven Schüle wrote:I say "never crash on external input".
My answer ... the code can be neater if full error checking is done in the first place and sometimes things have to be rewritten.
Part of that "error checking" topic can also be to include ASSERT's, which can sometimes help to reduce the amount of error checking code of the release version drastically. (But ASSERT's are not always the right solution, e.g. not always applicable for external input.)
To a certain degree this does also apply to chess programs, where an FEN parser is only one (perhaps less important) example.
Underestimating the need for error checking and/or ASSERT's is one of the best ways to unreliable code.
Sven
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: PGN parsing
What about opening a new thread for this one?Dave_N wrote:Ok so I am almost finished with the PGN parse error checking, is there anything wrong with this pattern matching code for the move strings format.
Sven
-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: PGN parsing
Changed my mind about posting the code
-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: Problem with bitboard knight attack generator
Probably the best practice, although in any app there are likely to be non-error checked assignments and variable usage. If for example you have a class called Foo ...Sven Schüle wrote:From my experience it is simply the wrong view to say that "fixing some error checking is a waste of time". It is always cheaper to include error checking immediately when designing the algorithm. If you add it later then you add much more testing effort, and there is a high risk that you introduce new errors by changing the algorithm (or its implementation) to include error checking. Better include it right from the beginning.Dave_N wrote:I think it depends on the project, if you have X amount of time until alpha (example: your software needs to have a working demo and you can use a laptop / video to show your investors) then why waste time fixing some error checking that is perfectly straightforward when you don't need a playable demo until beta testing, and even then you can wait for someone to complain about the bug because the official release doesn't happen until after a month of waiting for bug reports.sje wrote:This is the only good way of doing things. Long, long ago in school I learned the technique as "defensive programming", but by any name it's the best practice.Sven Schüle wrote:I say "never crash on external input".
My answer ... the code can be neater if full error checking is done in the first place and sometimes things have to be rewritten.
Part of that "error checking" topic can also be to include ASSERT's, which can sometimes help to reduce the amount of error checking code of the release version drastically. (But ASSERT's are not always the right solution, e.g. not always applicable for external input.)
To a certain degree this does also apply to chess programs, where an FEN parser is only one (perhaps less important) example.
Underestimating the need for error checking and/or ASSERT's is one of the best ways to unreliable code.
Sven
Code: Select all
class Foo
{
public:
Foo()
{
mem = new SmallBlockOfMemory(this); // new fails because the //system is out of memory
}
~Foo()
{
if( mem )
{
delete mem;
mem = NULL;
}
}
SmallBlockOfMemory *mem; // with own constructor
};
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: FEN parsing
But IsFenValid() needs to parse the FEN in order to validate it, so you parse it twice if it is valid. Usually parsing and error checking should be combined. Look how compilers work. They don't have two separate functions "IsProgramValid()" and "ProduceObjectCodeFromProgram()".Dave_N wrote:I actually think the only problem with the setFen issue was the question of where is the best place to error check the fen ?
if you assume a function has a working input and output then you don't call the function until you have called IsFenValid() for example.
Separating validity check and actual processing is best done if the validity check can be performed by looking at certain properties of the data to be processed, like for instance the size, or the range of some parameters. But if you need to look at the whole thing itself to decide whether it is valid then you are in fact doing almost the same work for validation and actual processing, so it should be done in one step.
There may be exceptions of course, e.g. if a separate validation is an external requirement.
Sven
-
- Posts: 1334
- Joined: Sun Jul 17, 2011 11:14 am
Re: Problem with bitboard knight attack generator
David,
stop.
Matthew:out
stop.
Matthew:out
Some believe in the almighty dollar.
I believe in the almighty printf statement.
I believe in the almighty printf statement.
-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: FEN parsing
but even though compilers have code-completion and intelli-sense they don't compile and link while the file is being edited. Although mistakes will be shown with red underlines.