Amy M Haddad

The Neglected First Step when Solving a Programming Problem

By: Amy M Haddad

image

The initial response most programmers have when starting a new problem is to open their editor and begin to code.

I used to do this, too. After all, don’t programmers program?!

They do.

But there’s a crucial first step that often gets neglected: taking time to think. Specifically, understand the problem before typing lines of code.

Solve the Right Problem

By thinking first, you can avoid working on the wrong problem, which, to my embarrassment, is something I have experience with.

When I was learning to program, I found myself solving the wrong problem on more than one occasion. The process was always the same.

I’d quickly read the problem statement and think to myself, “I know exactly what to do.” So I’d turn to my editor and start to code. I’d spend a lot of time experimenting with ideas that took me down long, random paths.

Hours later, I’d be frustrated by my progress and my broken code. So I’d turn back to the problem statement and re-read it slowly.

At that point, the feeling of dread would overcome me. I misread the problem statement or jumped to conclusions too quickly. Either way, I’d find myself working on the wrong problem because I didn’t take the necessary time up front to really understand it.

This happened a few times until I learned my lesson: think first, then do.

Avoid Unnecessary Roadblocks

Coding before thinking isn’t just a novice mistake. I soon realized that even seasoned programmers are guilty of it.

Several years ago, I was at a programming meetup in Boston. We were divided into small groups and given a problem to solve. My group of four consisted of programmers with decades of experience among us.

By that point, I’d gotten into the habit of actively thinking about problems, which I do with a notebook and pen. But I didn’t get to them.

The meetup leader had other ideas. Rather than giving us time to think, he immediately fired off questions about what he should type in order to solve the problem.

There was no thinking, only typing.

The rapid fire questioning and typing continued throughout the evening. Unsurprisingly, we ran into an excessive number of roadblocks because we never took a step back to think about the big picture. Instead, we got lost in the details.

As a result, the frustration was high, and the progress was slow. We were the only group that didn’t solve the problem that night.

Understand the Problem

This kind of situation can be avoided by understanding the problem. Do this by answering these questions:

  • What’s the problem asking me to do?
  • What information are you given?
  • What are your constraints?

Answers to these simple questions will give you great insights into the problem and what you need to do.

Aim to answer these questions out loud. It makes a difference. If what you’re saying doesn’t sound right, then you’re probably not on track. You may need to spend more time thinking.

Incremental Progress

Undoubtedly, understanding the problem will make your problem-solving process smoother.

But it’s not a hack.

You may still have challenges along the way, even with this knowledge. At least you know your destination, and you’re working toward it. Then, it’s just a matter of making incremental progress with the big picture in mind. As Albert Einstein put it: "If I had an hour to solve a problem I'd spend 55 minutes thinking about the problem and 5 minutes thinking about solutions."


← back to all posts