Good Observations, MichaelMarch 24 2008 at 12:06 AM
|Mac (Premier Login iorr5t)|
Response to Re: Some debugging techniques
> To do so without interrupting the program in the
> interpretor, you could replace
> To N = INT(RND * maxN)
> To with:
> To print cnt
> input N
> and enter a duplicate number, and see that cnt
> hasn't changed.
> Easier still would be to interrupt the program in the
> QBASIC interpretor. After executing
> N = INT(RND * maxN)
> once, comment it out and step through it with F8 to see
> that N = l(i) is considered true, and cnt isn't
> being incremented. This exploits the power of the
> interpretor, which is QBASIC's strongest advantage
> over other languages, IMO.
GOOD! The point being that the programmer has many options and should not get stuck on one way to debug. The main point of this thread is simply "there is at least one way to certify this program as totally debugged for all cases". Don't distribute bug prone code.
> DIM l(maxCNT) AS INTEGER
> This creates 1 more element than necessary. You could
> specify an lbound of 1, but it would be much better to
> specify a ubound of maxCNT - 1. If the latter option
> were taken, adjustments would need to be made,
> including putting l(i) = N before cnt = cnt + 1.
I generally just waste the element. It is very rare
that you run across the case that you need zero. I should, however, have coded
DIM l(1 to maxCNT) AS INTEGER
so that an element is not accidentally placed in l(0)
> FOR j = i TO maxCNT
> shouldn't that be:
> FOR j = i + 1 TO maxCNT
RIGHT! In fact, so right that I edited the program and changed
that line. Couldn't stand it.
> However, using CONSTs is a good idea for constants
> that may need to be adjusted. You only have to
> change 1 line instead of hunting through the whole
In fact I will go so far as to say "Never hard code when you can avoid it!"
Except for special cases of zero and one. These can safely be hard coded.
for i = 1 to max
is natural looking
for i = One to max
Well, books can be written and I have posted a lot of advice such as Advanced Design and Modular Debugging Techniques
|This message has been edited by iorr5t on Mar 24, 2008 12:13 AM|
Newbies usually go to www.qbasic.com and click on
The QBasic Forum
Forum regulars have their own ways, which include
The QBasic Community Forums