Philip Guo (Phil Guo, Philip J. Guo, Philip Jia Guo, pgbovine)

How to use assertions to make your code more reliable

In this excerpt from a classroom lecture, I introduce students to the idea of assertions using a JavaScript-based Web application as a running example.

Last year I wrote Code Carabiners, an article about how to use assertions to make software more reliable. John Regehr wrote a more rigorous and thoughtful article on this same topic.

In my Web Programming class this semester, I devoted an entire lecture to the topic of assertions, since they have saved me tremendous amounts of time when debugging. Although I used a JavaScript-based Web application as an example, the lessons generalize to programming in any language or domain.

I recorded this 40-minute video live during my lecture, chopped it up into five pieces, and lightly edited it. The delivery is a bit rough at parts, but overall I liked being recorded in front of a classroom audience rather than alone in a studio.

(full YouTube playlist)

Part 1 (Duration: 2:44)

The first step to becoming a better programmer is to get into the debugging mindset.

This clip features the blog post Who should I blame (when debugging)?

Part 2 (10:02)

What is an assertion, and when should you use it in your code?

Part 3 (10:07)

Here are some basic examples of assertions in my JavaScript-based Web application: an online resume editing tool.

Part 4 (8:19)

Here is a more complex kind of assertion in my Web application, which involves synchronizing multiple views of the same data.

Part 5 (10:05)

If an assertion fails, how do you build a reproducible test case to expose the bug, and then minimize that test case to make it easier for you to debug and fix it?

Donate to help with web hosting costs

Created: 2014-11-18
Last modified: 2014-12-18
Related pages tagged as programming: