What is debugging? How to identify and fix common errors in your application

sam
GEEKS FOR TECH
Published in
5 min readAug 12, 2020

What is debugging and why is it important? What are the tools that can help me as a junior developer?

This article was written in collaboration with my great friend, mentor and computer wizard Joaquín Tumas

What is debugging?

When trying to compile or run a program, it’s not inusual to find errors — these errors are popularly called bugs and the task of identifying and getting rid of them is almost an art for every developer. We’re going to see some main types of bugs:

Syntax errors

This is the simplest type of bug to solve. It happens in what we call compile time: the moment when we execute the compiler or the interpreter. As the name implies, we have a syntax problem — the language we are using requires that we comply with certain content structure rules and we are not doing so.

In the same way that in English it makes no sense to put two articles in a word, i.e. “the the thing”, in general any language will tell us that it’s wrong to use two operators in a row, such as:

const CONTENT == 'my content'

This invalid syntax in Javascript, and we can fix it removing the extra sign:

const CONTENT = 'my content'

Semantic errors

These errors refer to the semantics of what we’re writing, not the form, so they are harder to spot. The program will not detect these errors because it cannot know if the meaning (semantics) of what we are doing is correct and only the user, or a person who reads the code very carefully, will be able to detect it.

For example, try running this expression and see what it returns:

1 + 2 * 3 

You may be expecting a 9, because you know that in Math the order is: first multiplications, and then additions. But the computer won’t know this unless you are explicit about it. Try running this:

(1 + 2) * 3

Now we’ve solved the bug and we’re getting the expected result.

Runtime errors

These errors occur when an impossible operation is attempted during the program execution, such as dividing by 0. A runtime error can also happen when you’re trying to use an operation that is not allowed in a specific language, but it’s not a syntax error. Unlike semantic errors, this one will be detected by the computer: the interpreter will warn us of the error or the application will close and the operating system will warn us that something went wrong.

There may also be runtime errors due to invalid operations on system resources, such as wanting to use a piece of memory that does not exist. You can try dividing by zero using your preferred language and see what happens. Can you try and find some other ways of causing a runtime error?

Debugging tools

There are several tools that help us find, understand and fix bugs:

  • Linters: These are programs that review the source code and notify us if what we write does not meet the standards that we defined. A linter could detect, for instance, an ambiguous expression (despite having reasonable syntax). In the example of the addition and multiplication above, a linter could warn us that we should always use parentheses for arithmetic operations.
  • IDEs: this stands for Integrated Development Environment, or the text editors that we will use to code. In addition to allowing simple text editing, they usually have linters and auto-complete tools, which helps us write faster and with fewer errors.
  • Reading the code out loud: following what we write step by step can quickly expose us to finding whether what we wrote is what we wanted to write. Do you know what rubber duck debugging is? Look it up, it’s a very useful technique.
  • Error logs: when a running program ends abruptly or throws an error, it usually leaves some text explaining what happened, and these are called logs. Reviewing them in many cases allows us to instantly know what went wrong. Even if it doesn’t, it still gives us a good guide to know where to start investigating.

Conclusion

Whether you are a front-end or back-end developer, or even a full stack programmer (we’ll look into these categories in our next article), debugging is an essential skill. You need to have patience and develop your attention to detail and focus to be able to debug successfully, and it can be challenging even to more experienced professionals. Keep in mind that to debug you have to understand your code, what it does and what it’s supposed to do. A cool exercise to improve your debugging skills is looking at someone else’s bugs and have a colleague try and look at yours: this is going to be a pretty common thing in your professional career, so why not start early?

The complete series:

Thank you for reading this far! Sign up if you want to read more about technology, traveling, learning languages and living abroad.

--

--

sam
GEEKS FOR TECH

Front-end developer, passionate about UX and Angular.