What are some tips for learning how to code?
(This is a cross-post of a blog entry originally found here. It was written in 2014, but still holds up well today!)
I wanted to share some tips that will hopefully help if you’re about to start learning how to code. These tips are meant to alert you to potential obstacles and how to approach them; at the very least they’re meant to comfort you in the knowledge that you’re not the only one encountering these problems!
Before you begin coding
- In order to code, you need a development environment on your computer. This step is more painful than you might expect. Your computer most likely does not come ready out of the box to run code in the language you’re learning. If you’re trying to code Python with a Mac, you’re actually fairly lucky (in many more ways than one, as we’ll soon see) – Python is pre-installed on Macs, but you may want to upgrade to the latest version of Python before you begin. You may also have to install other development tools (such as the suite offered by Xcode for Macs), including package management helpers (such as Homebrew for Mac, or even language-specific ones like pip for Python). Then you might want some kind of text editor like Sublime Text, which has features like syntax error catching and autocompletion. And after all that, you then have to make sure that your computer’s system files are set up to accommodate all the new code you’ll be running (for Macs, this means, among other things, playing around with your .bash_profile)
- Corollary: Not all operating systems are created equal for coding. Which operating system you have has a drastic impact on how you set up your development environment. Mac users are in luck – Macs, based on the Unix operating system, are relatively friendly towards coding, and in fact are very popular choices for developers. Instructions on how to fix any problems are more likely to be Google-able and straightforward.
- If you plan on using Windows, setting up your development environment might be a bit messier. It is still do-able with all the resources available online, but you may also want to consider installing Linux alongside Windows and using that instead. Linux would be a new OS to learn and get comfortable with, but it has the advantages of being free, boot-able from a USB drive, and more straightforward to use.
- Having a motivating project makes a big difference. My learning curve did not really take off until I had actual projects from work to motivate me. There are many resources out there trying to provide a basic curriculum for any given language; these try all kinds of pedantic approaches, ranging from the hands-on “practice your code in this box we’re providing you” videos, to more gamified courses. These can be great for teaching the basics, but having a project that you will care about, one that you really want to see come into existence, will be a powerful motivating force.
As you’re beginning to code
- Documentation is your friend – really. There is a lot of good documentation out there, so that should be a resource you go back to in times of confusion. What’s even cooler is that most good documentation will have two extremely helpful characteristics: a set of “how to install” instructions, and examples of the code in action. Sometimes it can feel like the documentation itself is using so much jargon as to be meaningless; in these cases, try to skip ahead to the code example to see how things are supposed to work.
- Other people have probably had the same problem (aka Google and StackOverflow are also your friends). Problems you have early on in your process of learning how to code are ones that a lot of other people in the world have probably encountered as well. Thankfully, the internet knows the answer! One particularly good resource is StackOverflow, which allows users to post and answer coding-related questions (think Yahoo Answers, except way more legitimate and focused on computer science). If you’re ever stuck, just try searching for your problem (either the error message you’re seeing, or a description of the situation – remember to include which language you’re using!) on Google or StackOverflow.
While you’re coding
- Don’t forget about the source code. If you’re using any kind of package (for example, Django if you’re learning how to make a web app), don’t forget that the source code behind the package is likely available online on sites like Github, which is a popular code sharing / publishing and project version control resource. If you’re wondering why a package’s command doesn’t seem to be working for you, try looking at the code of the package itself (pro tip: the code tests that are part of well-written packages might have really useful examples of how the code is supposed to run).
- Interactive debugging is awesome. A good interactive debugger (e.g. ipdb for Python, or Pry for Ruby) will be a lifesaver. A debugger allows you to pause the code in the middle of running so that you can see information such as which variables are available at that point, what the values of those variables are, etc. This should probably be one of the first things you learn how to use once you learn the basic building blocks of your language of choice.
Above all, though, don’t be daunted by the idea of navigating this process by yourself: even if you don’t have a close friend who you can bother for coding help, there is a lot of well-organized, useful information on this topic online.