This handbook covers practices and tools from big to small. We’ll discuss how to write and organize modular code, how to write docs, how to make your code robust. We’ll finally reveal the correct number of spaces to use to indent code 1. At the end of the main lessons, we’ll go through an example project step-by-step.
This roadmap shows some of the concepts we’ll cover in the book. Take stock of where you are now. Come back to this figure after you’ve read parts of this book - you’ll be surprised how much you can learn in a few hours!
This book uses a number of conventions throughout. The command line is indicated by a
$ ls -al
The Python command prompt is indicated by
$ python >>> import antigravity
Sometimes I will ask you a question, and will hide the answer behind a spoilers panel. For example, what is the answer to life, the universe, and everything?
At the end of each main lesson, I ask you to put one of the lessons into practice through a 5-minute exercise. It looks like this:
Brush your teeth.
This handbook refers to code in several repositories:
True neutral cookie cutter:
Zipf’s law example project:
Source for the text of the book:
Tweaked sphinx book theme:
You can use these as references when you’re working on your own projects.
Breaking the cycle of frustration¶
Learning to code is a lifelong journey. The upper ceiling on programming skills is very high. Much like cooking, coding can be done on a purely utilitarian basis, or it can be elevated to high art. Professional programmers with decades of experience go on months-long retreats to acquire new skills. A good frame for getting better at coding is to think of it as a craft. Reading this book is a great way to refine your craft through focused practice 2.
When I talk to students about writing code, a lot of them describe feelings like:
Much of that frustration comes from a mismatch between what you want to accomplish (a lot) and what you have the ability to accomplish (not as much as you’d like). Programming instruction often emphasizes exploration, embracing errors as learning opportunities, and encouraging you to let your imagination run free. This theory of change implies that you will learn a lot by simply programming a lot every day. You might then feel guilty and inadequate when you’re not as proficient as you want after several years of daily programming.
In fact, unstructured exploration is a very inefficient way to learn a complex skill like programming. It’s like expecting a student to rediscover calculus by themselves after teaching them the rudiments of algebra! Research shows that structured instruction - like the one in this book - is far more effective at teaching programming skills 3. You’re taking the right step by reading this book!