UCSB Science Line
Sponge Spicules Nerve Cells Galaxy Abalone Shell Nickel Succinate X-ray Lens Lupine
UCSB Science Line
Home
How it Works
Ask a Question
Search Topics
Webcasts
Our Scientists
Science Links
Contact Information
How can you find glitches in programming without having to go through it manually and run the program a lot?
Question Date: 2016-10-24
Answer 1:

There are many ways to look for programming glitches or bugs--we call this debugging. You will probably still have to run the program, but if you set up your debugging strategy well, you won't have to spend as long doing it.

The simplest way to debug, called print debugging, is done by adding extra output to the code. This is often the fastest way to fix a problem. For example, if we have some guesses about what parts of the code cause a glitch, we can ask the program to print out the same information before and after each part. Then, when you run the program, if you notice that output changing, you know where the glitch started, so you can go back and take a closer look at what you wrote.

A lot of other debugging strategies are for code that already works and is being added to. For example, writing a unit test can be helpful for future changes you make to your program. A unit test is a separate piece of code that just runs important parts of your program and checks if they worked the way you expected. Every time you update your program, you run your unit test again, and you will quickly find out if the new changes broke something in it. A good unit test will save you time compared to running the full program manually a lot.



Click Here to return to the search form.

University of California, Santa Barbara Materials Research Laboratory National Science Foundation
This program is co-sponsored by the National Science Foundation and UCSB School-University Partnerships
Copyright © 2020 The Regents of the University of California,
All Rights Reserved.
UCSB Terms of Use