Learning to code
1 March 2020
By Nick H
Toward the end of last year, I decided that I was going to learn to code. I had a little experience playing around with R, a programming language used mainly for statistics, modelling, and data science, but lacked any real programming skills and had never made a concentrated effort to learn.
That all changed when I found myself consistently approaching tasks thinking, “There must be an easier way to do this.” Sometimes I wished that I could automate data analysis for university coursework. Other times I wished that I could build apps that were exactly suited to my needs and wants rather than fruitlessly scouring the Google Play store for hours. A lot of the time, I was just interested to see if I could actually do it: write programs to instantly solve problems that would otherwise take a long time to complete.[a]
So, from September to November, I learned the basics – and now I want to share how to do it with you. You’ll find below the answers to a couple of common questions, including a straight-forward, specific plan of what to do.
In this article.
(Scroll to location)
How much time should I put in per week?
It depends. I put in a lot of hours, but not nearly as many as some people recommend. YouTuber and self-taught programmer Andy Sterkowitz recommends a minimum of 2 hours per day, especially if you want to land a job in software development as soon as possible.
But many people can’t (or don’t want to) sacrifice this amount of time. I’m a full-time graduate student with 2 jobs and I didn’t want all my remaining free time each day going into coding. In my experience, weekends are good. A few evenings a week of 4 or 5 hours each are good. So are a few minutes here and there, whenever you can steal them. I wanted this to be a fun (although time-consuming) learning experiment and hobby, not a chore.
I’m sure that productivity gurus will tell you to space out your learning, to limit the length of time you spend on a session, and to do it consistently. If you have a lot of commitments, squeeze in 1 – 3 hours per day, Monday through Friday, and then at least 2 hours per day on the weekend. There’s probably some wisdom to that. With my schedule, it didn’t work for me. Do what works for you.
How much can I realistically learn in three months?
Some people with endless amounts of free time or unparalleled time management skills are able to blitz through several books and courses in three months and become marketable. For most of us though, the answer is: in three months, you will realistically learn the basics. By the end of three months, you will still be writing messy code, as I am. You will still be unaware of 99% of all there is to know. But you will have a firm foundation to continue to build, learn, and grow from. You will know how to think like a programmer and how to figure out solutions to problems you will encounter.
If you follow the plan below, in three months you will have a solid introductory grasp on Python, a popular, general-purpose programming language that is taught at universities and colleges around the world and used extensively in the marketplace, especially for data science, machine learning, and artificial intelligence. You will understand how to work with all sorts of different data structures, how to write efficient programs, and how object-oriented programming works, among many other things!
Which programming language should I choose?
The short answer is: Choose Python.
I suggest Python for a few reasons. As mentioned above: it’s extremely popular. However, the main reason is that it’s relatively easy to learn and hides some of the technicalities of programming that other languages will force you to deal with (it’s dynamically typed, for example). In addition, Python was designed with the intention of being easy to read, so much so that it sometimes reads almost like English. This makes it easy on the eyes to those unfamiliar with coding.
The long answer is: It doesn’t matter. Just pick one.
Really. Many beginners approach programming as though it were a single skill. In reality, however, programming involves many skills. For our purposes, let’s just consider the following two: writing code and computational thinking.
Computational thinking is far harder to learn and will comprise the bulk of learning to code, especially at the beginning. As a human, you have a humanlike way of solving and thinking about problems. You use inductive reasoning to reach your conclusions. But computers are not humans – they solve and “think about” problems in a totally different, totally logical way. The challenge of programming is figuring out how to translate your humanlike solution into a series of specific and repeatable steps that a computer can take.
To put it another way: I never ran into several-hour-long debugging sessions because I couldn’t write the code. It was always because I couldn’t formulate my ideas into a series of actions that the computer could understand. There’s a difference.
So just pick one. You’re not learning a language. You’re learning a way of thinking.
So, what’s the plan?
Getting started with coding can be difficult because there are so many resources online to get lost in. The abundance of resources is also a good thing, though, since you can learn almost anything in programming for free. My goal here is to provide you a short list of free resources to use which will start you comfortably on your journey.
If you’ve decided to learn Python, here’s what I recommend.
1. Watch tutorials online for beginners.
Watch Programming with Mosh’s Python Tutorial for Beginners. This course is six hours long, but I suggest watching online up until 03:55:34[b]. At that point, he moves on to some projects that you might have trouble following if you’re totally new to programming.
This course will introduce you to the syntax and many of the basic concepts of Python, including variables, functions, conditionals, loops, strings, lists, tuples, dictionaries, exceptions, classes, and more. Don’t worry if all of the content goes over your head. You won’t be able to implement all of these concepts in your own code yet. That’s okay. The goal at this stage is not to learn anything, per se. Rather, it’s to be exposed to everything that you’re going to learn in the next step.
2. Book resource.
Download and work through Think Python: How to Think Like a Computer Scientist by Allen Downey. This is a free book that is designed to introduce beginners to coding in Python. I found it easy-to-follow, detailed, and full of helpful exercises.
According to the book’s website, “It starts with basic concepts of programming, and is carefully designed to define all terms when they are first used and to develop each new concept in a logical progression. Larger pieces, like recursion and object-oriented programming are divided into a sequence of smaller steps and introduced over the course of several chapters.”
My strongest piece of advice with Think Python is: do all the exercises at the end of every chapter. The exercises are what make this resource stand out and completing them will be where most of your learning happens.
3. Further study.
Watch Unit 1 of MIT OpenCourseWare’s Introduction to Computer Science and Programming course.[c] Did you know that MIT makes a ton of tertiary-level course content available on the internet for free? This is the first of many in their computer science and programming series, complete with lectures, tutorials, assignments, quizzes, and even an exam.
I’d suggest doing this step concurrently with Think Python. If you wait until you finish the book before you start watching lectures, you’ll find the lectures boring. Use the lectures to cement what you’re learning in the book. I found that watching lectures was a welcome respite when I was sick of reading and that a second explanation really helped some concepts to stick.
If you’re interested in data science and statistics, go on to Units 2 and 3.
4. Build something!
Don’t get stuck in “tutorial purgatory”, only able to complete textbook exercises or follow along with other people’s code. Develop your ability to creatively use your programming abilities to solve multi-layered problems. Tech With Tim’s 5 Intermediate Python Projects might give you some ideas, including building a website with Django or Flask and building a game with Pygame.
Whatever you decide to build, choose something that you are interested in and passionate about. Think about why you wanted to learn to code in the first place. What kind of problems do you want to solve?
Do I really have to do all the Think Python exercises?
Yes. One of the biggest dangers in learning a concept in programming (or in anything) is thinking, Oh yeah, I get it, and moving on to something else before practising or implementing it yourself. So often, a concept makes perfect sense when explained in a textbook or by a tutorial on YouTube. Yet, when you come to try it on your own, you find yourself forgetting exactly how it is supposed to work.
This is why I don’t recommend simply following along with tutorials online. Many tutorials encourage you to copy code, which won’t work if you really want to understand what you’re writing. The best method for learning and remembering what you’ve learned is to learn the concept you need to solve a problem and then solving it on your own.
Don’t fall into the trap of copying someone else as they code and thinking that you’re learning. You may not have actually learned as much as you think with that method. If you do prefer using online tutorials, then after each coding walkthrough delete all your code and work through the problem again from scratch, this time on your own. I guarantee that, on your second pass, you’ll struggle to implement things you thought you had figured out the first time. And that’s good news, because it means you’re really learning. If you’re not struggling, you’re not learning.
In my opinion, the best way to learn to code is to read or watch an explanation of a programming concept, and then complete exercises on your own in which you implement your newly-gleaned knowledge. This is how Think Python works, which is why I recommend is so much.
What do I do next?
It depends. What are you interested in?
By now, you have the skills and knowledge to get into some intermediate concepts and projects in Python. You know how to learn on your own. If you want more coursework, try an MIT OpenCourseWare course. If you want to understand how to write efficient programmes, try Think Complexity by Allen Downey. If you’re interested in web applications, learn to use Django or Flask. If you’re interested in natural language processing, try the NTLK book.
There are countless options, so find something that you like and go for it!
a. There’s an anonymous quote that circulates online: “I will always choose a lazy person to do a difficult job because a lazy person will find an easy way to do it.” It’s often attributed to Henry Ford or Bill Gates, but no-one really knows who said it. Whoever it was, it seems like they understand programmers on a deep level.
b. If you watch on double-speed, you can do this in just 2 hours!
c. Again, double-speed is your friend here.