How To Think Like a Programmer
Learning how to code is challenging, that’s for sure. How can you make it easier for yourself? Learn to think like a programmer! The right mindset, mental models and problem-solving techniques make learning how to code a breeze.
Plenty of people who want to learn to code, give up early. That’s why skilled developers make five and six figure salaries. It’s also why there is a shortage of developers in just about any industry you can think of. The supply is low and the demand is high. How can you put yourself on that same track to success?
Here’s what we’ll get into:
- How coding is 80% debugging and just 20% writing new code
- The importance of finding your workflow for solving coding problems
- How deliberate practice and building coding projects can help you
- The advantages of an always-be-learning mindset
Let’s get to it!
- Mindset: 20% Coding, 80% Debugging
- Create Your Workflow for Problem Solving
- The Importance of Deliberate Practice
- Learn Something New Every Day
- Further Reading
Mindset: 20% Coding, 80% Debugging
Professional developers spend 20% of their time writing new code and 80% on debugging, testing and refactoring.
Finding bugs and fixing them can be frustrating work. Pick a random post on Stack Overflow and you’ll find at least one person complaining about how that one bug cost them hours of work.
Typical tasks you do as a software programmer consist of:
- Write a block of code, like a function or feature
- Test that bit of code manually – does it work OK?
- Write an automated unit test for the code (optionally, before you code it)
- Find bugs in the code and fix them one by one
- Test your code for “edge cases” – what happens when you do [unlikely thing]?
You also refactor the code you wrote before. Refactoring means rewriting the code so it has a better architecture1, better performance, and is easier to read. When you refactor, the result or output of the code doesn’t change.
Ideally, you also write unit tests so you can automate testing your code in the future. A unit test is essentially a pre-set condition that your code’s output needs to match to pass the test. Unit testing, refactoring and clean code are signs of a senior developer.
Refactoring can be complex, but it’s also easy to begin with. Did you write a new piece of code? At the end of the day, revisit the code that you wrote and see if you can improve it. Can you make it more clear how it works? What if you add a few code comments to help the reader (or yourself) understand your code?
You now see that it’s easy to spend 4 hours on debugging for every hour of writing new code. It’s important to incorporate debugging and refactoring into your mindset, because it helps you to think like a programmer. You don’t have to debug the code you didn’t write!
1 “Better architecture” here means rewriting for better structure, and making sure your code better follows the architectural patterns and design patterns you chose before coding the project.
Create Your Workflow for Problem Solving
Karl Popper, the great academic thinker and philosopher, has made an incredible contribution to scientific thinking: falsification.
Here’s how that works:
- In science you cannot be “right”, you can only aim to seek out evidence that refutes your hypotheses or ideas.
- Instead of testing theories to see if you’re right, you test them to see if you can prove them false.
Instead of thinking “Hey, I’m onto something here!” and looking for evidence that supports your ideas, you look for ways to prove yourself wrong. This way, the insights from one experiment moves our collective understanding forward.
You go from “All swans are white” to discovering black swans – and purple ones, for that matter – and you learn more about them along the way.
How does that tap into building iOS apps? It naturally leads to trial-and-error; of learning from your mistakes. We’ve discussed how debugging is an important task in software development. Trial-and-error helps you gain more insight when you’re problem-solving.
Consider the following scenario: You’re coding an iOS app with Swift. When you run the app, you get an error: “Found ‘nil’ while unwrapping optional”. Now what?
- You first seek to understand the problem you’re trying to solve. What’s an optional? What is
nil? What is unwrapping? You look that up, and learn more about these topics.
- Next up, you come up with a plan to test a hypothesis. Your idea is that somewhere in the code, an optional is improperly unwrapped and that causes the error. Your plan is to find the optional with debugging tools.
- The next step is of course taking action. You act out your experiment and gather results. Did you find the optional, and when you ran the app again, did you get any errors?
- Finally, you evaluate your results. You may for example have stumbled upon a solution that didn’t involve your original hypothesis. Can you go back and seek to understand how it works? And if you solved the issue, can you reiterate for yourself why it works like that?
The above strategy has many names: smart trial-and-error, Think-Plan-Act, experimentation. The idea here is to not brute-force the problem and try lots of solutions, but to combine problem-solving with gaining insight. Fixing the bug isn’t your only goal; you also want to learn more about iOS development.
This approach may not work for you, of course. Say you get a new TV and want to set it up, do you first read the manual or do you immediately start pressing buttons on the remote? Some people read the manual first; others go straight to trial-and-error. Find which strategy works best for you!
The fundamentals are the same, though. You want to grow your expertise with incremental improvements. You test your hypotheses and ideas, and learn from mistakes. You fail small (not too small), so you can succeed big. You develop your own workflow for problem solving, and that’s exactly how to think like a programmer!
The Importance of Deliberate Practice
Do a quick Google search and you’ll see that developers are in high demand these days. You see more than 2 million search results for “iOS developer jobs”, thousands of job posts on LinkedIn, and hundreds of pages with job descriptions of recruitment firms.
It’s no surprise that the top iOS development courses on Udemy have tens of thousands of students, at $10 a pop. But is $10 and 50 hours of video content all it takes to become an iOS developer?
Imagine that all those 40.000 students became successful iOS developers. There wouldn’t be a shortage of good developers any more! No, there’s something else going on…
Anders Ericsson, a Swedish psychologist who studied human performance, wrote about the 10.000 Hours Rule. This rule states that any one could master any skill, with no innate talent, given that you spent 10.000 hours to practice it. That’s about 10 years of practicing programming!
If you fill 10 years of practice with Udemy video courses, can anyone learn to code well and become a great developer?
As it turns out, time spent is only one of many determining factors. Aptitude, talent and mentoring all play a role, but what matters most of all is deliberate practice.
Deliberate practice is a simple concept. Are you racing through iOS tutorials and coding exercises as fast as you can, or are you deliberately examining, discovering and playing with code as you work through your 10, 100 or 1.000 hours of practice?
You get where this is going: learning to think like a programmer involves practice, too. A few ideas on how you can practice deliberately:
- Learn more about “break out” components, such as the UIViewController
- Dive into a Swift algorithm and use it to learn more about Swift syntax
- When you’ve learned about a new component, like URLSession, try to use it in your own iOS app project
Don’t code on auto-pilot, ticking off iOS tutorials from your to-do list. Improve your iOS development skills by going slow. Be patient, diligent, thoughtful. It looks like you’re going at a snail’s pace, but you’re really taking the time you need to get good at this.
It’s better to code the same app 10 times, improving it every time, than it is to code 10 apps once, and poorly. It’s like Bruce Lee says:
I fear not the person who has practiced 10,000 kicks once, but I fear the person who has practiced one kick 10,000 times.
Learn Something New Every Day
The difference between an iOS developer and a quitter is that the iOS developer is willing to learn something new every day.
”Willing” is key here. Many aspiring developers dream of a six figure salary, but not many of them are willing to put in the work. I get a dozen one-line emails a week from people asking how to make an app, but few of them go through the “trouble” of even trying to find this tutorial on my website.
It is the ability to make mistakes that defines the mindset of a successful developer. Thinking like a programmer is nothing more than a disposition to make mistakes and learn from them.
Surprised? Don’t forget that there are footsteps on the moon. They weren’t put there by people who wanted to go to the moon. They were put there by people that got to the moon!
The airplane from Paris to New York didn’t turn back when it realised that it was 2 degrees off course. It adjusted course, and kept adjusting its course, until it got to New York.
You can adjust course, and motivate yourself to keep going, by learning something new every day. It’s these small wins that compound over time. Not too small, not too big. Learning is a habit too, and habits help you achieve your goals.
An approach you can use to help yourself learn every day is, coincidentally, automation. You can automate your own behavior based on a neutral trigger.
Here’s an example: “Every morning, when I begin work, I spend 1 hour on Swift programming.” See how that works? You connect goal-based behavior with a trigger, such as getting out of bed, starting work or “When it’s Thursday 9 PM, I’m going to …” Such an automation helps you build a habit, and it prevents you from burning through your finite supply of willpower.
The difference between a junior and senior developer is that one of them is willing to make mistakes. But which one is it? The most astounding fact is that when you learn to code like this, learning to code is easy. It’s fun! Thinking like a developer makes all the difference.
Here’s a few brain-tickling coding tutorials for you to play with:
- Palindromes In Swift
- Converting Roman Numerals With Swift
- Binary Search In Swift
- Shuffling An Array In Swift Explained
- Insertion Sort In Swift
An incredible shorthand for thinking like a programmer is: ABT and ABL. Always be testing, always be learning. Put that on a Post-It on your desk somewhere, it’ll help you keep a great mindset!
Awesome! Now you know what it’s like to think like a programmer. It’ll help you learn to code, and write better code. Here’s what we’ve discussed:
- Focus on writing 20% new code, and 80% debugging/rewriting existing code
- Create your own workflow for problem-solving, based on trial-and-error, experimentation and gaining insights and understanding
- Deliberate practice is critically important to master a topic
- Automate learning something new every day – coding is fun that way!
And last but not least: cultivate your ability to put in the work by taking action. Go build something!
Want to learn more? Check out these resources:
Code Swift right in your browser!
Go to the Swift Sandbox