Debugging/Stack Trace

Steven Klavins
3 min readApr 12, 2020

Pesty bugs, they appear all over the place, I felt it may be worth doing a follow up on how we deal with bugs as their such a common issue for a developer. Part of an effective debugging process you could argue happens before the bug has even occurred, I shall cover some of these practices among others.

Logging/Printing to the console

Logging or printing to your console is an easy way to check values to see if your code is performing as expected. If you have a large program with many lines of code it is good practice to implement this in moderation where needed, this will assist in making your logs clear to read.

Effectively reading your stack Trace

What's the stack trace? Well if you’ve ever written a program you have most likely seen it. When a program fails in our IDE we get some lovely big red messages appearing in our consol, that is what we call the stack trace! The stack trace is useful as it attempts to tell us where our program is going wrong and the line the issue is occurring at. This is particularly useful for syntax errors among others, however, more complex issues tend to require further investigation.

Using a debugging tool

Many IDE’s these days are very well prepared in assisting you with bugs and there are a variety of very practical tools to choose from. IDE’s such a VS code have built-in debugging functionality which allows you to execute specific blocks of code and help you build almost what you could call a timeline. As you can imagine, building this visual representation of your code in your stack trace can aid greatly when debugging.

Implementation of TDD

Why not just test as you go? TDD is something I have covered at great length before and there is a reason why. When you lead with the idea of testing everything before you proceed you're far less likely to run into bugs further down the line. This is not a full-proof way to avoid bugs all together as you may still not get the expected outcome of your program, but hey that’s why combining this with behavior-driven development is a great idea!

Solid principals/DRY code

Dry (Don’t repeat yourself) Keeping your code clean and as flexible as possible can be a tricky task however it has endless benefits. Your code becomes easier to debug and modify as it's not tightly coupled. I encourage anyone wanting to program to learn these practices as they will help greatly, the video below is a great place to start and helped me learn what they're all about.

Minimal Code commenting

A simple yet effective skill is commenting on your code. This not only helps others understand what your code is trying to achieve, but it also reminds you.

Version Control / Comparision

Another subject I have covered a fair link is version control, having access to all versions of your code will help you out greatly when something goes wrong. Imagine you spent a month working on a project and in one day out of nowhere you are presented with countless bugs, with a previous version of your code you can compare it and identify where the new bugs were introduced.

Thanks for reading, will no doubt have many more blogs to come. If you wish to check out my previous blog on debugging for some additional information the link is here

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Steven Klavins
Steven Klavins

Written by Steven Klavins

Hi, I’m Steven, most call me Steve! I’m a programmer, musician, and artist. This blog contains various tutorials and posts related to software development.

No responses yet

Write a response