Debugging and/or commenting strategies please?

Just wondering if anyone has any simple debugging and/or commenting strategies.
I found I was forgetting what sections of my blocks were doing, so I created a list (Stored CommentList) and added a new item to the list for each step. That way I can see an explanation in the blocks and I can show the list in a list viewer for debugging. Because it’s a stored list when the app crashes I can also see the last thing it did before crashing. This approach is working, but would love to hear any other ways to do this that might be simpler?
Here’s an example of the blocks:

And here’s an example of the list of items that results:

1 Like

I think you need to separate the concepts. Comments are used to explain the code, and debugging is used to check the value of blocks.

You can add comments directly to blocks. They are usually written for the entire function. For this reason, each function should be as simple as possible and preferably contain only one action. In this case, you can achieve the effect of a self-documented function that is clear without comments.

If we talk about debugging, we need to display data on the screen. In other words, you must understand which block you are exploring and what value is stored in it. To do this, you can use Label, ListViewer, Alert, and other components that display data.

If you use global variables, you can easily get their values if you create an input field for their names.

I think the Alert component is best for debugging, since it is global.


Thanks for the quick reply @actech - I should have asked for help sooner. I had looked for and not found how to add comments to a block. I see how to do it now - via the contextual menu, so thanks for that.
When you suggest the alert function for debugging, do you mean something like if error, show alert? Or to take an example I’m working with - I’m using airtable to store profiles for users, downloading a sheet to a variable, then extracting specific pieces of data from the object using ‘get property’, then putting the data in the line into a list. This has led to crashes a few times, for example when I try to get a piece of data that doesn’t exist - usually because that field is empty. Would using an alert to flag when data doesn’t exist be a good approach in your opinion? So I’d check if the property exists before trying to get it and if it doesn’t pop up an alert?

When you suggest the alert function for debugging, do you mean something like if error, show alert?

I think you are a bit confused about what is debugging and what is error protection. Therefore, I will explain this point.

Debugging is the process of finding, localizing, and fixing errors. And error protection is the creation of error handlers. Simply put, when creating blocks, you always need to create blocks that protect the application from errors that occur. These blocks must check the existence of objects and data, the correctness of this data, the type of data, the readiness of data for their use, and so on.

Simply put, you can use Alert both to inform users when errors occur, and to display debugging information in it that users don’t need to show (users aren’t interested in the Fact that the x block has a Y value, since the developer debugs it to fix errors).

Instead of Alert, you can use Label and others for debugging, but Alert is more convenient.

As for your example, you correctly write that before using data or an object, you need to check their existence - this is error protection. Debugging is different. During debugging, you need to intentionally create situations where data is missing or its format or values are incorrect in order to find potential errors. Tests are also created for this purpose. But this is a more complex topic and it is not possible to test all applications within Thunkable X.

Do you understand what I mean?

Thanks @actech for your clear and very helpful response. I get the difference between error protection and debugging now. And am less confused!
I’ve tried using an alert and it is performing as you describe. I feel more confident now that I can build in the necessary error protection and find bugs. Thanks again.