11.12: Rapid Cycling Between Coding and Testing
selected template will load here
This action is not available.
If you think about the exercises we’ve done so far, you’ll realize that we started with an extremely simple script ( Script1.m ) that simply loaded a file, improved it ( Script2.m and Script2b.m ), and then added a bit more functionality ( Script3.m and Script4.m ). This is a good way to learn, but it’s also the way you should write your scripts. Don’t try to write 30 lines of code (or an entire script) without doing any testing along the way. If you write a 30-line script, you will probably have 8 different errors in the script, and it will be really hard to figure out what’s going wrong.
Instead, the best approach is to write a small amount of code, test it, debug it if necessary, and then add more code. At this point, you should be adding only 1-3 lines of code at a time. As you gain experience, you can write more lines before testing, but even an experienced programmer usually does some testing after every 20-40 new lines of code.
I almost put this piece of advice in a text box, but I decided that it's so important it deserves it's own section!