One of the first pieces of advice I got about learning a programming language was from Logan Hanks: “Read the library.” Then I read Derek Sivers’ advice to basically memorize the whole language.
I don’t really have the discipline to do either of these, frankly! However, what I’ve found to be very effective are drills. They’re similar to the flash card approach recommended by Derek, but slightly less modular.
- Make your way through a tutorial/chapter that teaches you some discrete, four-to-six-step skill.
- Write down those steps as succinctly and generically as possible.
- Put the tutorial/chapter and its solutions away.
- Build your project from scratch, peeking only when you’re stuck.
- Erase what you built.
- Do the project again.
- Drink some water.
- Erase what you built and do it again.
- A day or two later, delete your work and do it again — this time without peeking even once.
- Erase your work and do it again.
This method is particularly helpful for the Real Python course since it takes a project-driven approach, but it can be applied to any good Python book or course. Creating a project reinforces and builds upon existing skills, and prepares you for real-life coding challenges.
It may sound tedious (and obvious), but it feels great the first time you’re able to do the whole task from memory, and it tends to stick there, especially if you return to an old drill every now and then.
Just remember: This is how you learned to walk, read, throw a ball, and drive a stick shift (no?): You learned “on the job” rather than memorizing separate components of a given activity, and you used crutches until you didn’t need them anymore.
Drills are a weapon against intimidation
When I hit chapter six of Real Python book two, it felt a bit overwhelming. I had skipped over the database chapter in book one, and there were a lot of things going on:
- SQL syntax
- creating and populating databases
- joining tables
- mapping built-in SQL functions to a Python dictionary, then executing them from it
Looking back on it now, it doesn’t seem that dense, but it was tripping me up and not staying in my brain. So I devised a simple drill for the first three bullet points and put it in the corner of my screen:
- Create a database, and add a table with a few columns. One should be a quantity.
- Add a row to the table. Verify that it worked.
- Add several rows to the table using a list of tuples. Why is this the preferred method? Verify that the rows were written.
- Add another table with two common columns with the first table, and a “date” column, then populate it.
- Join the two tables to print combined rows of data where the values from the two common columns coincide.
SQL syntax was my first downfall: I had to peek to get the order of
INSERT INTO table_name VALUES(... and
CREATE TABLE pizza(topping_1 TEXT, topping_2 TEXT, quantity INT). Dot notation to select columns from multiple tables was pretty intuitive, but then I had to remember about
1 2 3 4 5 6 7 8 9 10
I like to use the command line shell for SQLite so I don’t have to leave my beloved command line; to each her own:
1 2 3
1 2 3 4 5 6 7 8
Verify those puppies, and then
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Success! Now, nuke that .py and do it again. Drink some water, go for a walk, do some squats, then
rm pizzas.py and… you know what to do.