Chapter 4: Learning to code

Learning to code is hard as there are many thorny choices to make.

Some common questions that may cause you unease:

What programming language will benefit me most? Learning the wrong language means wasted time.

Where do I learn from? Having so many resources to choose from is hard.

How do I show employers I have coding chops? This is a imperative to get interviews.

Let’s get you on track by answering these questions.

What programming language to learn

What do you learn if you have no programming knowledge?

You have a choice - Python or R? or SQL?

Structured Query Language, or SQL, is used to communicate with databases. It’s niche, but necessary for a data analyst to talk to databases.

R was created by two university professors in the early 1990s. R is used for statistics, to manipulate data, to plot graphs, and create machine learning models. It excels in these areas.

Python is a general purpose programming language. Python can do what R is able to, and much more. Python can also be used to create websites, games, desktop applications, and to automate tasks.

Python is more flexible than R. Even if you relinquish your data analyst dream, you can still use Python to build your own website.

Python also has a bigger and more active community than R. More people are working to create new Python libraries or improve existing ones. A library is a chunk of reusable code. Most useful libraries concentrate around a single topic. Crypto, climate models, or plotting graphs.

Using a specialized library expediates your work. Imagine that you’re creating video editing software. Install the MoviePy library and you’re able to cut, concatenate, and do video compositing. Manual instructions to the computer is not needed.

Python, with more libraries and more use cases, is more future proof than R.

Should you learn Python or SQL first?

SQL is very different from Python. SQL is “non-procedural” whereas Python is “procedural”.

By procedural, I mean Python (and almost all other computer languages), works like a recipe: step 1, step 2, etc. This also makes debugging in Python much easier.

Most people are used to the idea of recipes, hence Python might be a better way to start.

SQL concepts are also present in Python. You won’t need the operational features of SQL at the start, so learning Python first is preferable.

It is also easier to practice Python than SQL. It’s harder to set up a fake database to practice SQL, than to create a Python environment.

Python is also well developed for Object Oriented Programming (OOP), so if you need to learn some other OOP language in the future (like C++, Java, etc.) Python will hold you in good stead.

All things being equal, I’d say learning Python is probably the best choice, but it really depends on your own goals and background.

How to start learning Python?

Elon Musk is a prolific learner. He started as a software engineer and went on to transform the most competitive (automotive) and complicated (aerospace) industries. Musk created PayPal, and now runs Tesla Motors and SolarCity - companies that make a clean, renewable energy future a reality. He also owns SpaceX, a space exploration company with a vision to colonize Mars.

Musk was asked on Reddit how he learnt so much in such short periods. Here’s what he said:

I think most people can learn a lot more than they think they can. They sell themselves short without trying. One bit of advice: it is important to view knowledge as sort of a semantic tree — make sure you understand the fundamental principles, ie the trunk and big branches, before you get into the leaves/details or there is nothing for them to hang on to.

Let’s apply Musk’s advice to learn Python.

Level 0 to 1

You’re considered a newbie when you first starting learning something new. You don’t know what you don’t know. You will feel anxiety and uncertainty. Questions like “am I missing anything?” and “I have no idea what this means” will frequently appear.

At this stage, the goal is go from

level 0: “don’t know what you don’t know”, to

level 1: “knowing what you don’t know”

Why this goal? Knowing what you don’t know is like having a map and compass - you know which direction you have to walk towards. All you have to do is take action.

To climb from level 0 to level 1, start broad.

Find a comprehensive Python course. I find video courses ideal to introduce programming concepts. I watch the videos at 1.5 to 2x speed.

I recommend this Udemy course and this Udemy course.

Follow along any exercises by actually typing out code. This helps you to get used to Python syntax. Syntax is grammar for programming languages.

For concepts that you find difficult to grasp, be proactive and google the concepts for a clearer explanation.

When you feel overwhelmed by too many new concepts, pause. Take a break. Take your mind off Python. Walk, jog or talk. You can always come back to the course when you’re refreshed. Having a diffused mode of thinking is as important to learning as staying focused.

Remember to pause after each section too. Make a mental recall of what you’ve learnt. As much as you can. If you experience a nagging feeling of a concept that you can’t remember, watch the video again or google the concept. Doing this helps chunk new information into your long term memory. It’s supposed to feel hard. In fact, the harder it feels, the more effective you’re learning.

Do a mental recall what you’ve learnt at the end of the course. Don’t despair if you are confused at the end of the course - this is expected. You’ll internalize more by recalling than by blinding watching the videos again. Even if you feel there is a lot you cannot remember.

If you’re followed the pointers above, you’ve levelled up from 0 to 1. When you encounter any foreign concept in Python in future, you’ll at least know where to look and you’ll have roots to cling on to that can help kickstart your investigation.

Now, get to work and finish the course.

Get some general practice

Since you’re at level 1, you’re aware about programming concepts but you also know that there is plenty more to know. Right now, the concepts are like a faint light grey squiggle in your brain. You can likely recall what each concept entails, but you likely won’t know how or when to apply the concept.

The goal is to darken the squiggle and make it a bolded black line; solidifying when and how to apply each concept so that it becomes a handy tool in your programming toolbox.

Some important programming concepts:

  • Data types (lists, dictionaries, tuples)
  • Loops (“for” loop, “while” loop)
  • Statements (“if”, “with”, “try” etc..)
  • Variables
  • Functions
  • Classes
  • Using python modules or libraries

You grow programming muscles through practice. Why not make practice fun? Why not build something you want to instead of what an online tutorial tells you to? Chart your own path. Choose a practical project that solves a problem you have. Record the logical steps needed to build the project, and tackle one step at a time. It’s like building a grand Lego tower by stacking one Lego block on top of the ones below.

You will face uncertainty at each step. What is the syntax for a “for” loop? When do I use “try” and “except”? Get proficient at Googling. Understand how questions are asked on stack overflow and how to find good answers.

But don’t make finding the right project a big deal. It’s better to start something small and simple than to remain undecided for too long. Here is a list of 42 project ideas to start. Three salient points to keep in mind when you’re creating:

1) Think through the logic of each project yourself. This helps you learn when and how to apply a concept. For example, you choose when to use a “for” loop instead of a “while” loop in a specific context. When you get stuck, take a break. And then try to break down the project into even smaller steps. Only when you’ve taken a few breaks or get mighty sick Googling then should you look at code that someone else has written. You’ve done “just in time” learning of programming concepts. Learning this way is effective.

2) Quantity trumps quality. Creating more projects is better than creating a perfect project. A university photography class was split into two groups. One group had to submit their best picture at the end of the school term, while the other group was graded based on how many pictures they submitted. The latter group which produced a larger quantity also consistently produced the best looking pictures.

3) Create a variety of projects. Build a calculator, then generate a random Wiki article, then automate your spreadsheets. Each project exposes you to different python libraries and APIs. Variety builds a base. When you encounter a new problem in future, it will look familiar because you can recall a past project which had similar concepts.

A soft reminder again: don’t forget to have fun building what you want. Behold the vast possibilities that programming bestows.