This is the fourth and last big idea in my series on programming effectively, which is based on my new learning tool, Programmer’s Pyramid. Each article contains one big idea and one or more ways to apply it. In case you missed the last one, you can read it here.
We’re often in such a rush to move on to the next new problem or program. But hold on for a minute.
Just because you’ve solved a problem doesn’t mean you’ve learned from it. This is important to do because you’ll likely see a related problem in the future, so nail the concepts and spot the patterns now.
You do this by taking time to “look back,” as mathematician George Pólya puts it in his book, How to Solve It. Really understand what you wrote and why. Solidify concepts that may need a bit more work.
And, as Pólya suggests, see if you can improve your solution: “We could improve any solution,” writes Pólya, “and, in any case, we can always improve our understanding of the solution.”
The next problem you solve, take some time and “look back” by applying the tactics that follow.
1. Study the solutions of others who’ve solved the same problem.
After you complete a problem, study the code of others who’ve solved the same problem.
If you want to take it up a notch, I suggest that you apply a learning technique that Ben Franklin used to become a better writer, where he tried to reproduce an article from a publication he admired — after he’d forgotten the details of it.
Here’s how Franklin’s learning tactic works when applied to programming:
- Solve a problem.
- Find a programmer who’s solved the same problem.
- Study their solution. Read each line of code and type a comment in your editor to summarize it.
- Let some time pass, and then re-solve the program. Use the comments you typed out as hints to guide you along the way.
- Compare your new solution to the one you studied.
This practice is an excellent way to get better at reading code, add new tools to your programming toolbox, and solidify concepts.
2. Add a constraint.
Say you solved a problem using a while loop. Now try solving it using a for loop. Or try using recursion.
The idea is two-fold: to get outside of your comfort zone and to gain another perspective. That way, the next time you encounter a similar situation, you’ll be ready: you’ll have several tools at your disposal.