How to Solve any Programming Problem

A simple guide on how to think like a programmer

Before Semicolon
Mar 18 · 10 min read

As humans, we solve problems all the time and as developers, it is no different. Problem-solving-focused courses are not very popular or common and a lot of developers tend to focus on learning tools, languages, and frameworks rather than learning how to think like a problem solver, a programmer.

What is Problem Solving?

Due to convenience, when you take your broken car to the shop they may decide to fix what is broken, replace the broken part, or offer the option for you to buy a new car altogether. Even though all these options seem like a “solution”, only the first one is actually dealing with the problem. Everything else is avoiding having to deal with the problem.

As developers, there may be times you have to decide to avoid the problem completely and replace it with something new instead of dealing with the problem, but this article is focused on techniques to solve the problem and not replace or avoid it.

You solve a problem when given a set of constraints and having to follow some rules you come up with a solution that meets all the constraints and does not break the rules. As programmers, we write a program, a set of instructions that solves the problem.

To Code is different than To Solve Problem

Solving problem is a different skillset and as humans, we are naturally good at it. I mean, we built the world around us by solving problem after problem. What developers often struggle with is connecting these 2 skillset. Solving programming problems makes you better at solving real-world problems and if you are good at solving real-world problems, programming may come naturally to you.

Why not many courses on this?

Just because you understand the tools in the toolbox does not mean you can fix a car, but knowledge of the toolset and a problem-solving strategy and mindset may allow you to fix a car eventually.

What coding tutorials are good for is expose you to as many problems and solutions as possible as a way to teach you how to program. Developers tend to freak out when they don't find the video or the blog post with the answer and that's why they post on forums or social media websites like Reddit and StackOverflow.

Before the popularity of the internet, programmers had to actually find a solution for the problem they were dealing with. Back then, having a problem-solving strategy and mindset was essential and nowadays developers tend to neglect this skillset because they can just google the solutions.

This convenience of the internet made learning how to program easier and something you don't even have to go to school for but also flooded the industry with a lot of developers that can code but don't have the problem-solving strategy mindset.

Common Problem Solving Mistakes

It’s nobody’s fault actually. If you stop to think about how people are learning to program nowadays, you realize that is basically by clicking on a video and get the exact solution you need. Naively, you may try to do the same thing when trying to solve problems on your own.

What is often not obvious is that in order to put together a tutorial video, an instructor often goes through a process backed up by years of experience and exposure to many problems and solutions which makes it easy for him/her to walk you through the solution without having to explain how they reached that solution.

No, the tutorials are not bad things and you should not stop watching tutorials or google for solutions. Even pro developers do the same thing. What I am trying to make you understand is that you should put some time and effort into learning the process and plan your solution before you dive deep into coding.

So how do you solve problems?

Some problem solutions may even require you to create your own tool or system. That’s why big frameworks, tools, and systems are born in high-level jobs and tech companies. Facebook introduced React and GraphQl, Google developers created Angular and Dart, Microsoft gave us Typescript, etc. This shows that when you actually engage in solving a problem it may lead to new tools or systems that can be shared with others.

Every problem solver has a method, a step-by-step guide to reach the solution, and that’s what you need to become familiar with. Actually, your brain already knows this but it reaches solutions so fast that you often dont think about how it got there. To solve problems you need to slow down and gain control over the anxiety to reach the solution quickly.

You solve problems with a good problem approach strategy by analyzing, studying, and planning solutions, sometimes multiple ones. It may take time and requires patience. So let’s break it down.

Understand the problem

If you can explain a problem in simple words to someone else and they get it, then you understand it. It is good to write down your understanding, sketch, make diagrams, etc. Often times other developers call me to their desk to help them solve something and just by trying to explain it to me they figure out the solution.

Your brain often gets stuck in some particular details that sometimes prevents you from seeing the bigger picture and by trying to explain it, sketch it, and breaking it down, you force your brain to grab more details that enrich your understanding of the problem.

The way you confirm your understanding of the problem may be by repeating it back to the person introducing you to the problem or by having confirmation on the details you collected.

Always Plan a solution first

You can do it by writing comments, high-level pseudocode, a diagram, flowchart, more detailed sketches, etc. The purpose of the planning phase is to see the bigger picture and identify all the subproblems, steps, and parts of the problem.

Your plan may change during the solution implementation or get replaced with something totally different as you go. The idea that spending time on a plan that may be scratched later may seem like a waste of time, but the simple step of planning for something gives you the idea of the whole thing and makes it much easier to adapt on the fly later on.

It is impossible to predict the whole outcome in one plan and that's why plans may change or get abandoned as soon as you work on implementing them. Without a plan, you are simply rolling the dice and hoping to get lucky. Lacking a plan makes it hard to delegate or welcome people into the solution as well.

Start with what you know

Identify patterns

Once you identify the patterns, you already solved the problem. If changes are required, you will have a starting point to continue from.

Start with the most constraints first

This is equivalent to buying a new house. You list all your constraints first; how much you can put down, how many bedrooms and bathrooms, area, budget, size, etc. Once you have all your details down you narrow your options making it much clearer to see what you can afford. If not satisfied, it will be equally obvious what you need to work on to change your options.

Divide the problem

Simplify the problem

Experiment

Maybe there is a library that can help you solve the problem but you are not familiar with. Maybe you are expecting a result but got something totally different. Experimentation is a particularly great way to approach bug fixes. In general, it is a good approach to explore a problem to try to understand it more or to test different options to compare which can be a better solution.

Backup and state the problem

Once you get frustrated you tend to complicate things, fail or pick a complex solution for the problem. Walk away for the day or for hours, take a deep breath and explain the problem back to you out loud. Sketch what is going on to check your understanding of the problem. Solving problems should be a logical thing and not an emotional one.

Practice

Conclusion

With a problem-solving mindset, anything is possible. Write down these steps and try to follow them in your next problem-solving adventure until you memorize them. There are many websites that allow you to test your problem-solving skills for FREE that you should try. For more concrete examples and details, read the book below.

This article was inspired by the book “Think Like a Programmer” by Anton Spraul.

YouTube Channel: Before Semicolon
Website: beforesemicolon.com

Geek Culture

Proud to geek out. Follow to join our +500K monthly readers.

Before Semicolon

Written by

Blog & YouTube Channel for Web, UI & Software Development - beforesemicolon.com — youtube.com/c/BeforeSemicolon — Writer: Elson Correia

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Before Semicolon

Written by

Blog & YouTube Channel for Web, UI & Software Development - beforesemicolon.com — youtube.com/c/BeforeSemicolon — Writer: Elson Correia

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store