General Problem-Solving Techniques
At its heart, programming is about problem solving. Anton Spraul has put it nicely into words some problem solving technique. I’ve found it very useful to trigger programming mindset. Enjoy!
- Always Have a Plan
This is perhaps the most important rule. You must always have a plan, rather than engaging in directionless activity.
Restate the Problem
Restating a problem can produce valuable results. In some cases, a problem that looks very difficult may seem easy when stated in a different way or using different terms. Restating a problem is like circling the base of a hill that you must climb; before starting your climb, why not check out the hill from every angle to see whether there’s an easier way up?
Divide the Problem
Finding a way to divide a problem into steps or phases can make the problem much easier. If you can divide a problem into two pieces, you might think that each piece would be half as difficult to solve as the original whole, but usually, it’s even easier than that.
Start with What You Know
You should try to start with what you already know how to do and work outward from there. Once you have divided the problem up into pieces, for example, go ahead and complete any pieces you already know how to code. Having a working partial solution may spark ideas about the rest of the problem.
Reduce the Problem
With this technique, when faced with a problem you are unable to solve, you reduce the scope of the problem, by either adding or removing constraints, to produce a problem that you do know how to solve.
Look for Analogies
An analogy, for our purposes, is a similarity between a current problem and a problem already solved that can be exploited to help solve the current problem.
Sometimes the best way to make progress is to try things and observe the results. Note that experimentation is not the same as guessing. When you guess, you type some code and hope that it works, having no strong belief that it will. An experiment is a controlled process. You hypothesize what will happen when certain code is executed, try it out, and see whether your hypothesis is correct. From these observations, you gain information that will help you solve the original problem.
Don’t Get Frustrated
The final technique isn’t so much a technique, but a maxim: Don’t get frustrated. When you are frustrated, you won’t think as clearly, you won’t work as efficiently, and everything will take longer and seem harder. Even worse, frustration tends to feed on itself, so that what begins as mild irritation ends as outright anger.
Think Like a Programmer by Anton Spraul