Skip to 0 minutes and 11 seconds In the last week’s session about defensive programming we talked about best practices for writing clean code and producing high quality documentation. However, your code will contain bugs. You have a tool that can actually help you to catch those bugs early, and it may surprise you, it is your compiler. A compiler has a lot of options and flags that will warn you about suspicious code. However, you need to know how to interpret the warning messages generated by the compiler and hence, how to fix your code accordingly. For some programming languages additional tools are available which capabilities go beyond that of compilers. For instance, for C and C++ there is a Cppcheck which we’ll cover here as well.
Skip to 1 minute and 9 seconds Donald Knuth once said, “Beware of the above code; I have proved it’s correct but I’ve not tried it.” To paraphrase, “Code that has not been tested does not work.” It’s very important to write good tests for your code, both unit tests and functional tests. We’ll talk about best practices and also about frameworks that help you to write those tests easily and to run them conveniently. However, you may wonder whether you have tested your entire code base. Now, let’s say that the answer is probably “no.”
Skip to 1 minute and 57 seconds You can use a code coverage tool in order to check which parts of your code have been executed and which have not been executed and adapt your unit tests in order to get a better coverage. In summary, in this week’s section we’ll focus on catching bugs early before they can do any real damage.
Introduction to Week 2
Week 2 learning goals
During this week, you’ll learn about
- Unit testing,
- Code coverage tools,
- Using the compiler to warn about suspicious code,
- Static code analysers.