Chapter 9: Incremental development

Test as you code

face Josiah Wang

You should always test your code to make sure that:

  1. Your code is working (no syntax errors)
  2. Your code is working correctly (it behaves as expected)

How do you test your code? I hear you ask.

You might be thinking of “testing” as something separate from the coding process.

There is also a different (and arguably better) way of thinking about testing.

You should always test your code while you are coding.

What do I mean by that?

What I mean is that you should not be writing your full code in one go, and then only run and test your code.

You will quite likely encounter lots of errors doing it this way. You will also find it harder to debug errors in your code, since the error might occur at any point in your very large program. Then you will be frustrated, feel overwhelmed, panic, cry, and feel like hitting your head on your computer, etc.

Testing your program only after you complete it = frustration!

A better way to approach writing your code is to make sure that your code always works!

This means that after writing one line of code, make sure that the code works, and that it works correctly as expected.