up previous next
1.1.13 Tutorial: programming and debugging
This tutorial is for those who have little experience in
programming and debugging.
Despite one's best efforts any non-trivial program may easily contain "bugs".
When this happens one must somehow locate the fault,
and then find a way to rectify it.
The CoCoA interpreter does not offer a special debugger.
A good guideline is to split your program into smaller pieces,
each of which has a clearly defined purpose which can be described succinctly.
Then these pieces can be tested, and fixed, independently.
Understanding how to split the program becomes easier with more experience.
Try to find a simple input where your program misbehaves:
this is not always easy, and may require quite some time!
When you have a manageable troublesome input, you should insert
some print commands in your code saying where execution has reached,
and the values of some variables.
println "Start of function Blah: input A = ", A, " and B = ", B;
println "After doing XYZ: poly has degree ", deg(f);
The mistake might in the input, and the program is correct:
double-check that the input really is what you intended!
It may also happen that the problem lies in CoCoA.
Check carefully the CoCoA manual to see whether the function actually
does what you think it does!
If you are quite sure the problem lies inside CoCoA then see
Tutorial: feedback and reporting bugs