/ Learning to code

How to think like a programmer

A common misconception that people have about programmers is that they know everything. But, in reality, that's not quite the case. What programmers do have is a unique approach to solving problems and, in this article, we’ll explore what that programmer mentality is all about. Plus, we’ll share tips to help you get there, too.

What is the programming mentality?

Let's think about programming as speaking for a moment. When you speak, you’re aiming to communicate effectively with the people around you. When you program, you’re aiming to communicate with a machine. In both cases, you don’t need to know every single word or element of a language, you just need to know enough that you convey your ideas so that they are understood.

When you use code to solve a problem, it’s less about memorizing snippets of code and using them. It’s more about knowing the fundamentals and applying them. When you understand how to break a problem down into smaller pieces and apply the principles of programming, you don’t need to memorize everything. You simply learn how to approach a challenge or problem, and that is a skill you can apply every time you code.

Break things down into building blocks

Let’s look at a simple example of how you break a problem down into its building blocks, like a programmer approaches a problem.

If you were to describe to a machine (or a person who’s new to a task) how to open a jar of pickles, you couldn’t just say “open jar.” You'll need to explain in a language they understand the steps required to open that jar. For example, you might offer the following set of instructions:

  1. Pick up jar with left hand
  2. Put right hand over the lid
  3. Tighten both hands
  4. Rotate right hand counterclockwise, and rotate left hand clockwise
  5. Rotate until lid separates from bottom jar
  6. Release tension in both hands

Simple tips to get you thinking like a programmer

Everyone’s programmer perspective is different; meaning, each each programmer thinks in a different way and learns how to approach and break down problems uniquely. Through practice, you'll develop your programming perspective, and it'll get easier to communicate with machines to solve increasingly complex problems.

As you develop your own perspective, here are a few tips and tricks you can use to learn to think like a programmer and develop this mentality.

1. Talk through the problem aloud

First, you can talk through the problem by calling up a friend or family member and explaining to them what you’re trying to tackle. By having a conversation with someone, you’ll be able to determine how you can communicate with them to clearly explain the problem and your solution.

Don’t have anyone to talk to right now? No problem! Just try speaking through the problem out loud. Explain your approach and understanding to your pets or even a stuffed animal. It’s speaking aloud that is the key.

2. Collaborate (work with other programmers)

Programmers don’t always work by themselves at their computers. They like to learn from each other. When the problem is complex, working with other programmers helps bring together the best ideas from many people, making it easier to come up with innovative solutions.

Try pair programming, which is when two programmers share a computer to solve a problem together. One programmer (the driver) writes the code, and the other (the navigator) reviews the code and directs how the problem is broken down and solved. Every few minutes, the two switch roles. This gives you the chance to see another programming perspective at work. How your partner solves a problem will be different from you, and this helps expand your mindset and learn to approach problems from multiple angles.

3. Take it one step at a time

Whether you are programming or starting on any big project, large problems can seem scary at first, and it’s easy to get overwhelmed. The best way to combat this feeling is to look at the problem from a high level and then break it down into smaller chunks.

Just like we talked about earlier, when you split a problem down into smaller pieces, you can then apply the fundamentals of programming to solve each piece. Approach each chunk of work separately so that the task is manageable, and you can start to make some real progress, one step at a time.

4. Start simply: how would you solve a similar, simpler problem?

You can also consider how you might solve a problem that is similar to what you’re attempting to solve, but much simpler. Then write the code to solve that small problem. Slowly but surely, introduce complexity to solve the larger problem you were presented with at the beginning.

5. Practice, don’t memorize

Memorizing code is tough, and you don’t need to go down that road to think like a programmer. Instead, focus on the fundamentals. Learn the principles and ideas behind programming, and you’ll get much further than trying to remember everything.

Every time you solve a simple problem using programming, you’ll develop your fundamentals even further, making it easier as you progress. Codecademy’s optional problems and projects are a great place to start. Practice is key to your programming perspective becoming second nature.

6. Don’t worry if you need to look up the right syntax

Even some of the best programmers around need to look up syntax when they don’t remember things. So don’t sweat it if you need to search online or in developer documentation for the syntax that you need.

In fact, the co-founder of React, Dan Abramov, wrote a blog post about how people often think he knows more than he does. The moral of the story is that you don’t need to be an expert at all things, because you can program if you know the fundamentals, and we’re all capable of learning new things.

7. Shortcuts can be dangerous

Taking shortcuts while you’re learning to program can be more hurtful than helpful. Try to think of the learning process like running tennis drills. You could take steroids to get stronger and become a better player, but that’s likely to hurt you in the long run.

Rather than searching for an answer right away when you encounter a problem, try to solve it yourself first. When you rely on other people’s coding solutions, you don’t get to develop that programming muscle yourself.

Focus on the basics, put in the practice, and run your drills. The tried and true training methods are that for a reason; they work! We know that it can be frustrating when it takes time to learn to program, but that’s all part of the process of forming your own programming perspective.

8. Get help after you’ve exhausted other options

If you’ve really tried your hardest and approached the problem from many different perspectives, but you’re still struggling, now’s the time to ask for help. Reach out to a colleague or teacher or post on a forum to get some guidance.

It’s more likely you won’t be robbed of a learning opportunity when you wait to ask for help until you really need it.

9. Debugging tests your knowledge

Debugging your own code allows you to take a step back and see the opportunities for improvement in your own work. It can be easy to blame the machine every time something goes wrong. But if you take a moment and analyze how you’re approaching the problem, you can see where you might have gone wrong. Understanding this will help you to identify errors in the future quicker, and you’ll naturally get better by avoiding these issues in the long run.

10. Get familiar with reading documentation and applying it to your code

Documentation for programming is just like a recipe for cooking. It lays out how the code is intended to work and is an excellent resource to help you understand programming better. Learning to read documentation will also steer you away from looking for a shortcut or an easy solution to your problems or bugs.

Putting your programming into practice

If you’re itching to start practicing to learn how to think like a programmer, we have some resources to help. Head to the Codecademy Forums for a list of resources for practicing what you've learned on Codecademy.

Remember to focus on how to solve a problem and to learn as you go. Don’t get hung up on needing to do things “right” or to be “perfect.” There are many ways to solve a problem, and, with practice, you'll build your own unique programming perspective!

Get more practice, more projects, and more guidance.

How to think like a programmer
Share this