Debugging: The Problem Solving Approach (Life And Code)

Emmanuel Unyime
The Startup
Published in
5 min readSep 2, 2020

Earlier this year, I was asked to give a short lecture in front of my colleagues, a daunting 400+ students, a lecture on Debugging, and since then, my approach to Web development and living have changed.

(Disclaimer: There will be a lot of pasta talk.)

Debugging is the process of checking previous chunks of code you’ve written, for errors. For reasons, like prevent unexpected behaviours, getting your code to work, and getting it to work better.

Make it work, then make it better and faster — Gabriel Alexander Stephen

It was an impromptu presentation, I had studied for it but didn’t actually think I would get called to do it that day. I was shocked to see that people enjoyed my presentation.

Talking to people about programming isn’t easy, it’s hard to keep their attention and honestly if you’ve come this far, I’m impressed. So what did I say exactly?

Programming is Daily Life

That didn’t take much convincing as it is actually true, in my other article “What I Learnt Trying to Build Two Apps Using JavaScript”. I was able to talk about some of the approaches I use to code that is applicable to life. But more than that, concepts like object oriented programming (creating re usable objects) to functional programming (functions that use objects to achieve output) are derivatives of life’s behaviour. Cooking for example implements the use of recipes and cooking methods that to achieve outputs. And just like Programming, there is a certain flexibility, there are many ways to cook pasta as there are many ways create a function to take inputs and perform arithmetic on them.

Sometimes it takes more time to debug a program than to code it.

So how exactly do we Debug Life and code.

A while ago, I was working on a project that selectively isolates job applicants on the basis of their qualifications, but in my case I could only take it one parameter. This brings me to the first thing I did:

  1. Identify The Problem

You need to identify what exactly the problem is, are you unable to keep up a good habit, or is the pasta you’re cooking too salty ?

2. Understand The Nature Of The Problem

There are four types of problems, you have to classify your problem, the reason is, this makes it the solution come easier and with clarity.

  • A SIMPLE PROBLEM

It’s a problem where you fully understand it and you have something up your sleeve that can solve it, then go ahead and do that. Example:

LIFE: You want the pasta to taste a certain way.

CODE: If I wanted to click a button to display the color red.

  • A COMPLICATED PROBLEM

This is the kind of problem where you have a known unknown. You have to take steps to acquire that unknown, provided you know what it is. It’s a problem that when solved is basically turns into a simple problem.

LIFE: You want to season the pasta but you don’t have the salt.

CODE: I want to write Javascript but I don’t have a script tag open or I don’t have a javascript file.

  • COMPLEX PROBLEM

This a problem where you can only figure out afterward why what happened happened. Here you have to take some sort of action to see what happens before you act again. This is as real as debugging gets, the behavior of your project after you’ve taken certain steps.

LIFE: So you taste the pasta, and you’ve noticed, it’s not salty enough or too salty.

CODE: I click the button but I’m getting an error message.

That process of clicking and tasting, is the action that helps you understand a complex problem.

Ask yourself what is the nature of your problem? This is the actual first step to debugging.

Upon contact with a problem, take account of everything, from the states of the program, variables and values at the time it happens.

3. Take Actions

Based on identifying the nature of the problem you can then go on with solutions.

Examples from Number 2

In the SIMPLE PROBLEM

You want the pasta to taste a certain way - salting it would be the solution.

If I wanted to click a button to display the color red - then I have to add a function that works on clicking that button.

In the COMPLICATED PROBLEM

You want to season the pasta but you don’t have salt — so you have to take steps to acquire salt, buying for example sounds good enough, or go to the North Atlantic and from it’s salt water, extract salt. But maybe some other time, for now you’re hungry for pasta

I want to write Javascript but I don’t have a script tag open or I don’t have a javascript file — I create a javascript file so that I can write the code for the button, so it performs a function.

In the COMPLEX PROBLEM

So you taste the pasta, and you’ve noticed, it’s not salty enough or too salty — and then you decide that adding water to dilute it’s salty nature or, adding more salt to increase it’s salinity is good enough

I click the button but I’m getting an error — so I have to go back and pinpoint the error in code. Maybe there’s an omitted ‘}’ on line 32 as usual. So you fix that and you have click the button again, to verify your solution.

4. That’s Not Alll

Have you ever written a sentence but by changing one word, most especially a verb, the nature of the whole sentence changes. You have too look out for that, by salting your pasta, you can make the food less peppery. Or by adding a curly brace to the end of one line you have to remove another down the line.

Fix the existing bug, but also check that any new bug does not occur.

Some problem will take longer than others to implement this process, but it is one of the best blueprints for solving problems either in life situations or on line 32 of your Javascript file.

Note : Debugging isn’t always fixing a problem, you can create counter measures to prevent with problems in the future, a sort of preventive maintenance or measures to accommodate problems (a factor of safety), a sort of adaptive maintenance.

So at any point in time, take a moment to debug, yourself and/or your code.

--

--