Debugging

Debugging


Sooner or later, you will get stuck, annoyed, frustrated, confused, or some other form of negative emotions when your code just does not work and you don’t know why. This is normal. You can choose to handle these situations calmly and focus on trying to solve the issues. There are several ways to approach this. Here are some recommendations

Read the error messages #

The p5.js error messages are generally very helpful. Try to understand what the message says and use the reference to unpack what you might be doing wrong.

Google (or your favorite search engine) #

wisdom_of_the_ancients.png

Rubber Duck Debugging #

We called it the Rubber Duck method of debugging. It goes like this:

  1. Beg, borrow, steal, buy, fabricate or otherwise obtain a rubber duck (bathtub variety)
  2. Place rubber duck on desk and inform it you are just going to go over some code with it, if that’s all right.
  3. Explain to the duck what you code is supposed to do, and then go into detail and explain things line by line
  4. At some point you will tell the duck what you are doing next and then realise that that is not in fact what you are actually doing. The duck will sit there serenely, happy in the knowledge that it has helped you on your way.

Works every time. Actually, if you don’t have a rubber duck you could at a pinch ask a fellow programmer or engineer to sit in.

Andy from lists.ethernal.org

Your own duck #

One of the top perks of choosing this beginner group is that you will get your own rubber duck to help you on your coding journey. Name them, take care of them, talk to them, you can give your duck tattoos or other decorations.

DuckGPT #

In cases when your duck is not around you, there is an online variety of the duck, DuckGPT. It is very realistic!

p5.js Guide to Debugging #

There is a nice illustrated guide available from p5.js on debugging.

Matti #

After you have exhausted all other options (or sometimes earlier), you can come ask help from Matti.

LLMs (ChatGPT etc.) #

AI tools are also incredibly capable in helping you out to figure out problems in your code. Note that sometimes they make up things, invent libraries or functions that don’t exist, or generally just get things wrong. Do not trust them blindly, and most importantly ask more questions when you don’t understand something. Do not use LLMs to write ready code for you, use them to understand why things are done in a certain way.