Test As You Work

Execute your program often. I like to execute my program basically every time I make a change to the code. Each time you execute, you are checking that your program does what it is supposed to be doing. If you make a whole bunch of changes between executions, you will have a hard time remembering to check that each one of those changes is working. And if one of your changes breaks your program, you will have a very difficult time figuring out which change is guilty. I have made the mistake of writing a lot of code at once and testing at the end. I sometimes write a bunch of code without testing, all the while thinking, “I know what I’m doing. All of this will work.” On rare occasions (three in the last seven years), it all does ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.