Basic debugging
We have been happily coding along. The big moment has arrived; it is time to run our program. We run our program and find the results are not as we expected them to be. In fact, something is grossly wrong. Our inputs and outputs are not matching up. So, how do we figure out what went wrong? Well, having bugs appear in our programs is something that we all face as developers. However, there is some basic debugging that we can perform to aid us in remediating or, at the very least, gathering information about these bugs:
- Printing out code markers in the code:
Markers in our code are
print
statements that help us to identify where we are in the program when the bug occurred:fmt.Println("We are in function calculateGPA")
- Printing out the type of the variable:
While debugging, it might be useful to know the variable type that we are evaluating:
fmt.Printf("fname is of type %T\n", fname)
- Printing out the value of the variable:
Along with knowing...