How to really learn Go

How to really learn Go

witch-learning copy.png

A student’s handbook

I teach Go for a living at my software engineering school, the Bitfield Institute of Technology, and I’m writing this post partly as advice for my students, but I think much of it applies to anyone who’s trying to learn Go, or indeed anything at all. Consider this your Student’s Handbook for Go University.

What follows are a few tips which I’ve found useful myself, and which I give to everybody who studies with me; if you read them, think about them, and (don’t forget this step) apply them, you’ll find they will not only speed up your progress dramatically, but they’ll make a real difference to your ability to learn and master Go.

You might also find my tips on time management useful.

1. Practice every day

For 37 years I’ve practiced 14 hours a day, and now they call me a genius.

—Pablo de Sarasate

Every musician or martial artist knows this, and so does anyone who’s successfully learned some difficult craft or skill. You need to practice every day. If you do, you’ll make far more rapid progress, and probably get much further, than someone who just puts in two or three sessions a week.

You can still make some progress studying once a week, but it will be terribly slow, and you’ll spend most of your time just making up the ground you’ve lost in between sessions.

“Practice every day”: easy to say, of course, but difficult to achieve in reality, at least for those of us with busy lives (which is all of us). The Tiny Habits book advises us to “take baby steps” when trying to establish a new habit. This is a great idea.

Don’t start out trying to do an hour a day, for example; this just isn’t sustainable. None of us have a spare hour in our day, just waiting for some activity like Go learning to fill it. Instead, start with 15 minutes a day. That may not sound like enough time to learn anything useful, but that’s not the point. The point is to establish the habit of daily practice.

Pick a time of day when you tend to have the most mental energy and focus (usually earlier in the day, rather than later). Set yourself a repeating appointment in your calendar for a 15-minute Go session; if possible, at the same time every day. That makes the habit easier to establish.

When the appointed time comes, put yourself into “Go mode”: sit down at your computer, open your code editor, and load your current project. You may not feel like doing anything at all. That’s normal. Your goal is simply to spend the 15 minutes in a situation where you can study or practice Go.

If all you do is stare at your program for 15 minutes and then turn the computer off, that’s okay. You’ve done it. You’ve won. Just keep doing this every day. Your sole purpose is to convince your brain that these regular sessions are important, and something it needs to do.

If you can keep up the daily sessions for two weeks, you’ll almost certainly find that it becomes much less effort, and requires less willpower, to start each session. Eventually, it will become normal and natural, and not something you need to effort yourself into, and you’ll find you don’t really want to stop after the prescribed 15 minutes (that’s okay. You don’t have to!)

2: Write code

Remove wrapper, open mouth, insert muffin, eat.

—7-11 muffin instructions

There are lots of ways to study a programming language like Go: you can read books, watch videos, read tutorials and blog posts; all of these are valuable. But by far the most effective way to learn to write Go is to write Go. Don’t do quizzes or timed interview challenges, don’t answer multiple-choice questions, instead write a program.

It literally doesn’t matter what the program is about. In fact, you shouldn’t even worry about trying to pick useful projects; just write some Go that does anything. The point is to exercise your Go muscles. You should still do this even if you write Go every day at work; you need to have a project with no stakes, no expectations, no deadline, and where you can do whatever you want, which doesn’t tend to be true of work projects.

Here are some ideas:

Your project doesn’t need to be unique, innovative, challenging, useful, or even interesting (okay, it helps if it’s interesting). Just do something. Print out the prime numbers, or count the number of files in a directory, or play tic-tac-toe, or Conway’s Game of Life, or draw the Mandelbrot set. You get the idea. Pick a project, and start.

3: Read code

The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility.

—Edsger W. Dijkstra, “The Humble Programmer”

There are very few successful writers who’ve written more books than they’ve read. The same applies to programmers. Writing good code is largely a matter of having good taste, and the way to develop good taste is to read other people’s programs, both good and bad.

Explore GitHub for Go projects; pick things at random that look interesting, and start reading. Read the documentation, read the code. Ideally, clone the repository and browse it using your own editor, with its Go-specific facilities for navigating and annotating code.

Read big programs, like Kubernetes, or Terraform, or Go itself. Read little programs by beginners. Read the code in the standard library. Read solutions to programming challenges. Read the source for command-line tools, or web browsers, or operating systems. Learn how projects are put together, how code is organised, and how functions and types are named and grouped together.

Start a Code Club with friends or colleagues where you each read a piece of Go code, and discuss it. What was interesting about it? What was new to you? What didn’t you understand? What did you think might be wrong, or could be improved? What ideas could you borrow for your own programs? What introduced you to a whole new topic you’d never heard of before?

Students sometimes ask “But how do I read code? Do I start at the first line of the first file and work through in sequence? Do I skim-read or go line by line? Do I follow every function call, or understand the high-level stuff first, then go deeper?”

Basically, do whatever works for you, but a good starting point is to find the main function, if there is one, or the entry point of the library, and proceed from there following the normal execution of the program.

Read each line of code carefully. If you understand that line completely, go on to the next. If you don’t, look again and think about it. Check the documentation or the language spec if you can’t understand what’s happening. If you get completely stuck, make a note of the problematic function or line, and move on. Follow up on your notes later by asking a colleague or mentor if they can understand the tricky bit and explain it to you.

The more code you read, the more you’ll be able to write. No idea is new or original; everything is borrowed from somewhere else. You are building up a store of concepts, techniques, and tricks that you can draw on when it comes to your own programs. Don’t read books, read code. (Well, do read books, of course, but don’t fool yourself that it’s a substitute for careful, thoughtful, code reading).

4: Manage your time

In truth, people can generally make time for what they choose to do; it is not really the time but the will that is lacking.

—John Lubbock

This might seem an odd one; what’s time management got to do with Go? The answer is, a lot. Time management is, succinctly, learning how to spend your time on stuff you want to do, and not on stuff you don’t.

Ever said to someone, “I really want to learn Go, but I just don’t have the time”? Here’s a question: how many hours of TV do you watch in a week? (Yes, Netflix and YouTube count as TV.) Now, I’m not putting down TV (or podcasts, or movies, or audiobooks, or Facebook, or Hacker News, or any other form of on-demand entertainment); it’s great. Sometimes you just need to unwind. But for how long?

Try this experiment for one week: make a note of every hour you spend watching TV, scrolling through social media or news sites, or otherwise passively consuming entertainment, and review it at the end of the week. What does it add up to? Fifteen, twenty hours? More? Did you really intend to spend all that time on entertainment, or did it just sort of happen by accident?

Could you take, say, just two of those hours a week, and spend them on 15-minute daily study sessions instead? How much more rewarding would it be to look back on a week’s learning than a week’s binge-watching?

There are 168 hours in a week (fun fact). How you spend them is at least partly up to you. Sure, you’re busy; everybody’s busy. As Thoreau said, the ants are busy too. The question is, what are we busy about?

Be punctual, not just for your study sessions, but for everything. If you’re five minutes late here, ten minutes late there, it all adds up. Sooner or later you’re hours behind where you meant to be, and you can’t afford to lose that time. And being late for things is a classic tell: it means you’re not managing your time properly.

5: Pick a direction

Steering is more important than speed, in driving and in software development.

—Ron Jeffries

It’s important to take some time to figure out where you want your career to go.

Do you want to land a job as a developer or infrastructure engineer? Do you want to move to a more interesting role within your current company? Do you want to feel more confident and productive in the job you have? Do you want to contribute to open source projects? Or do you simply enjoy the mental challenge and fun of programming as a hobby?

These are all the right answer; the point is to ask the question. Once you know why you’re learning Go, you can figure out which direction to take. You’ll never learn Go completely, in the sense of mastering the discipline to the point where there’s nothing you don’t know. Instead, we’re all on a learning journey that will last a lifetime. The question you need to answer now is where are you heading?

If you’re applying, or preparing to apply, for Go dev jobs, find five or ten vacancies which you can realistically see yourself interviewing for. What specific skills or knowledge do they need? Do you have it? What experience is necessary? Do you have that experience? If not, how could you get it? If they ask for related skills such as networking, databases, or cloud, do you feel you’ve got that stuff covered? What could you do to boost your knowledge in these areas?

If you want to write programs for fun, what kind of programs? Where do you feel unconfident or lacking in knowledge and experience? What sort of projects would help you gain it? Are there existing projects you could contribute to?

None of us have as much time or energy as we’d like to; the key is knowing how to prioritise what we have. In your 15 minutes today, what are you going to study? Have a list of topics, tasks, and projects prepared, so you can just dive straight in and get to work. Check things off as you cover them; each checkmark takes you one step closer to where you want to go.

6: Make a plan

I try to take one day at a time, but sometimes several days attack me at once.

—Ashleigh Brilliant, “I Try to Take One Day at a Time”

When you’ve worked out the big things you want to learn, or the competencies you want to attain, break them down into smaller steps. For example, you might say “By the end of January, I want to feel really confident I understand concurrency in Go.” Make a plan for how to achieve this: week by week, day by day. Assume things won’t go to plan. That’s normal. You’ll need to constantly re-evaluate, adjust, and update the plan as you go; what matters is to have the plan.

Plan each day. This really helps. Okay, certain things are already blocked out: work, meetings, taking the kids to school. But you still have some open spaces in your schedule; if you don’t fill them, someone else will. Make a rough plan at the start of each day, first thing, before the day can attack you. “Before work I’ll be studying Go, after lunch I’ll be doing this work project, from 2 to 2.30 I’ll be catching up on emails”, and so on. Planning what you’ll be doing literally every hour of the day sounds borderline obsessive-compulsive, but trust me. It works.

Check the plan throughout the day to remind yourself what you intended to do at this time. You won’t be able to do all of it. Stuff comes up; that’s just a given. But if you can push back on it to the extent of carving out an extra half an hour or an hour of intentional work or study, you’ve won. Do the same again tomorrow.

Review your plans at the end of the week. How did you do? What went right? What knocked you off course? What will you do better next week?

Every month, review what you intended to achieve. Did you achieve it? (Probably not entirely, but don’t sweat it; you’ll have done a thousand percent more than if you hadn’t made a plan.)

7: Learn things

Study hard what interests you the most in the most undisciplined, irreverent and original manner possible.

—Richard Feynman

A common question among Go students is “what should I study?” Yes, Go, but what specifically? You can’t learn everything, so where should you start?

If you’re a beginner, focus first on getting as much practice as you can simply writing Go code. Once you feel reasonably confident and fluent with Go, start filling in the knowledge gaps. Read the Go spec and look for things you didn’t know, or don’t feel confident you could explain to someone else. Study and practice those things.

Look at Go’s standard library. Are you familiar with all of it? If not, look deeper. Read the docs. Think you know the fmt library? Keep reading until you’ve found at least one thing you didn’t know about. Use it in a program.

Get practice building bigger projects, designing package APIs, and writing libraries. Figure out what makes a program readable, flexible, extensible, maintainable, scalable. Study other people’s projects. How do they work? What lessons could you apply to your own code?

Read around the subject. Build your general tech knowledge. Find out how compilers work, what’s inside a CPU, where TCP/IP comes from, what the HTTP protocol says. Learn about HTML, JSON, the Unix shell, computer graphics, disks, databases. Study algorithms, data structures, math, programming language design, debuggers, SQL, operating systems, distributed systems, infrastructure.

It literally isn’t possible to know too much about software engineering. It’s easy to be put off by people who write knowledgeable-sounding books or blog posts, but don’t be. They started out in the exact same place as you, and they just sat down and learned stuff. You can too.

8: Exercise

One day’s exposure to mountains is better than a cartload of books.

—John Muir

Wait, what? How is exercise going to help you learn anything? If you’re already short on time, shouldn’t you spend every available minute coding or reading, instead of flinging kettlebells around?

No. That leads to burnout. Richard Steele wrote that “reading is to the mind what exercise is to the body”, and those two things go together. If you neglect the body, the mind will suffer, and vice versa.

Physical exercise has a powerful effect on your mood, energy, motivation, quality of sleep, focus, and mental sharpness. As a student, you need to make a special effort to get regular exercise; it’s a force multiplier for your study sessions.

Do something strenuous every day, whether it’s walking, climbing stairs, lifting weights, jogging, cycling, yoga, martial arts, sport, or… well, use your imagination. Anything that gets your heart pumping and breaks a sweat is good. You don’t need much. Half an hour a day is fine, and it’s half an hour more exercise than the vast majority of people get.

Don’t bother joining a gym; you won’t go. Instead, make the world your gym. Walk to work or the shops instead of driving. Take the stairs instead of the lift. Use a standing desk. Get some weights or resistance bands and work out with them when you’re watching TV. If you see a hill, walk up it. When you’re on a long Zoom meeting, do jumping jacks (put yourself on mute first).

9: Eat well

Having enough to eat: that is joy. Knowing when one is full: that is wisdom.

—Deng Ming-Dao

Eat good food, and not too much. Don’t starve yourself or binge; have some balance in your diet. You don’t have to live on brown rice; that’s not what your body was built for. Instead, eat sensibly, in moderation, and learn how to listen to your body. It knows what it needs.

Eat when you’re hungry, sleep when you’re tired. Know when to push yourself, and when to rest. You don’t drive your car everywhere at a hundred miles an hour until it breaks down; don’t try to do the same with your body.

Cook meals instead of eating processed foods. Yes, cooking takes time, preparation, and planning (so does learning Go). But it’s also fun, especially if you do it in company. When you cook, make enough for three meals. Eat one, refrigerate one, freeze one. Today you earned your dinner, but tomorrow and the day after, magic meals will just appear as if from nowhere!

10: Be still

The mind is only a vehicle. When we don’t need our legs we don’t use them. Likewise, let the mind rest when not needed.

—Jean Klein

Every minute of every day, we’re assailed on all sides by noise, people, traffic, conversation, phone calls, text messages, emails, interruptions, crying babies, breaking news. This non-stop assault has a serious impact on our mental well-being, and that relates directly to our ability to think, study, and learn.

Have you ever wanted to do some study or programming, but just felt like you haven’t got the energy? Your brain just doesn’t want to co-operate. Instead, it craves the sugary stimulation of Twitter, or texting, or TV. You and me both.

The human brain actually needs a non-zero amount of peace and silence in order to function properly. But unless you live on top of a mountain, or perhaps under the sea, genuine silence is really hard to achieve. Everybody wants a piece of your attention, and unless you push back—hard—they’ll simply keep taking until there’s nothing left.

The good news is that you can make space for yourself to just be. Everyone can. Call it “meditation”, “quiet time”, “just sitting”, or whatever you want. It doesn’t matter what you call it: it only matters that you take a few minutes every day just to be still and quiet.

Some people find it conducive to sit, or stand, or lie down. Some prefer to take a long walk. For some, jogging or cycling is their meditation. Your mileage may vary. The point is to give your brain a chance to slow down and cool off, without being constantly pinged and poked at.

At first you’ll find it helpful to get well away from other people: shut yourself in a room (the bathroom can work, provided you don’t hog it for too long). Failing that, sit in your car, or go to the park, or find a grove of trees.

Turn your phone off, or leave it behind. Most phones have a ‘do not disturb’ mode, where you can block all calls and messages, but still allow specific people to reach you (your partner, your kids, your transplant surgeon). Use it.

If you have a partner or a family, tell them about your need for quiet time, and get them to help you by protecting it. Maybe they’d like some quiet time too. You could try all being quiet together; that’s actually kind of fun.

Here’s a very important warning: the first few times you try to be quiet and still, it will be really difficult. Your brain is just not used to its own company. All kinds of crazy thoughts will keep popping into your head. You will feel bored, antsy, uncomfortable, even anxious. You will have incredibly strong urges to just quit and do something else (specifically, to check your phone). Don’t feel bad. This is normal.

So again, don’t try to do too much at first. Aim for fifteen minutes. Set your phone alarm or kitchen timer (ideally, not one of those really harsh and jarring ones) and sit still for the allotted time. If you genuinely can’t do fifteen minutes, that’s okay (most people probably can’t at first). See how many minutes you can do (maybe five), and tomorrow, try to do one more, and the day after, one more than that.

Don’t try to make yourself calm, or empty your mind, or breathe a certain way, or anything like that. Don’t use a meditation app, or ambient music, or whale song. Just sit, and let yourself be with yourself for a while. There’s really nothing to it (and that’s the point). If you’re efforting, you’re doing it wrong. This is one thing in life you can’t succeed or fail at, because you’re not doing anything at all. If you’re sitting, you’re winning.

Thoughts will enter your mind and go round and round; the more you try to push them away, the more fuss they will make, so stop pushing and let them come. You’ll find that if you don’t fight them, they will just pass over you and drift away, like clouds across the sky. After a while, your brain will run out of thoughts and give up, and you’ll find that you naturally become calm, without any struggle or effort. The only way to win is not to fight.

If something really important, urgent, or valuable occurs to you, don’t start thinking about it, and don’t try to remember it: just write it down. (Keep a notebook or a pen and paper for this purpose; don’t use your phone.) Once your brain knows that the thought has been saved for later, it won’t waste any further energy thinking it.

If you make the effort to carve out just a few minutes peace and quiet for yourself every day, you’ll find it rapidly gets easier, and you stop getting the unmanageable desire to quit. Even though your brain is not used to the silence, that’s what it wants, what it craves.

Your brain has been denied this peace and quiet for perhaps your entire life. Once it starts getting it, it’s like an addiction: you’ll want more, and still more. Eventually you won’t need to make a special time and place for silence. You’ll find life is full of opportunities for mini-meditations: when you’re waiting for the lights to change, or the meeting to start, or the bus to arrive. And when you do get some time to yourself, you’ll be comfortable just walking, or just sitting and being, without any kind of external stimulation or distraction, alone with yourself.

You’ll find you have more mental energy, it’ll be easier to motivate yourself to study, and you’ll make more progress and retain more when you do. You’ll sleep better, and longer. You’ll be more productive when you’re at work, and more relaxed when you’re not. You’ll want to evangelise the benefits of meditation to everyone you meet. (Don’t do this, it’s annoying. Instead of telling everyone about the joy of silence, just be it yourself. Sooner or later, they will get the idea, and try it themselves, or they won’t. It’s all good.)

Ten commandments of Go

Ten commandments of Go

Go vs Python

Go vs Python

0