Gallery
Kuovonne's Guide to Scripting in Airtable
Share
Explore
Developing Generic Coding Skills

Debugging & Testing

Your donations tell Kuovonne that you value her content and want her to continue publishing.

Debugging syntax errors

When code does not even run, the problem is usually a syntax error. Syntax errors are often tiny—a difference of one character, such as missing or extra punctuation, or a spelling/capitalization error.
Some code editors flag syntax errors for you. However, the place to fix a syntax error is not necessarily where the computer notices the error. For example, the computer may tell you that a closing brace is missing, but it probably cannot tell you where the closing brace belongs.
To fix syntax errors, look for
punctuation errors (missing comma, extra closing brace, etc.)
spelling errors (misspelled variable, capitalization difference)
If you experience the following after making a small change in previously working code, you may have introduced a syntax issue.
Many new error flags from the code editor, far away from the actual code changes.
Wildly new and unexpected results.

Debugging logic errors

Logic errors usually are the result of one or more of the following:
The logic in the code is different from what the coder thinks it is. For example, a misplaced closing brace might change which code is executed in a particular block, a poorly written condition might be evaluated as true when it should be false, or a function might have unexpected side effects.
The value of a variable does not match what the coder thinks it is. For example, a library function might return different value or data type from what the coder expects.
The code does not have the actual logic that the situation needs. These cases require returning to the drawing board and identifying the correct logic.
A common method of debugging logic issues is to log what the code does as it runs, including the values of relevant variables at the time. Then compare what really happens with what you expect.
If you aren’t sure where to start, log when each code block starts, and when each variable changes value.
When logging variables, be sure to log the name of the variable and its data type, not just its value.
Pay special attention to objects with nested values. Check each level of nesting.
If a variable has an unexpected value, identify why it has that value.
If a section of code is not running when it should (or vice versa), identify why.

Test cases

Test simple cases—start with simple tests on small parts so that you can identify issues early.
Test common cases—since the common cases are what will be used the most often, make sure the results for these cases are right.
Test complex cases—how does your code handle the most complex example that you reasonably expect?
Test edge cases—what happens if any inputs are outside the expected ranges?

Scalability

What happens if your code has to handle much larger or smaller batches of data?
What happens if there is no data for your code to process?
What happens if there is too much data for your code to process?
The content in this guide is free, but creating it takes time and money. If you like this content, .

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.