Dear friends,
I’d like to share a programming tip that I’ve used for years. A large part of programming involves googling for code snippets you need on Stack Overflow and other websites. (Shh. Don’t tell the nondevelopers. ????) But that’s not enough if your goal is to maximize your own learning. When the relevant code snippet is just several lines, rather than copy-pasting them from a web page into my code, I usually retype them myself. The physical practice helps train my brain to internalize the concept and syntax.
To gain skill as a programmer, you need to internalize both the concepts and the syntax. When I’m trying to help friends get started on coding, I ask them to type print(“Hello World”). By typing it out, you can be sure you know the command’s syntax, such as whether it requires parentheses ( ), square brackets [ ], and so on.
You can’t learn to ride a bicycle by reading a book on the theory of bicycling. You have to do it yourself! Coding is more similar to this type of physical skill than most people realize, and practice makes perfect.
When you’re trying to master a programming technique, consider these practices:
- Read a line of code, then type it out yourself. (Bonus points for doing it without looking at the reference code while typing.)
- Learn about an algorithm, then try to implement it yourself.
- Read a research paper and try to replicate the published result.
- Learn a piece of math or a theorem and try to derive it yourself starting with a blank piece of paper.
Many creative artists start by replicating the works of artists who came before; so, too, in coding. By replicating examples of good programming (being mindful of copyright and attribution, of course), your brain masters the ability to create them. This frees you to focus on higher-level tasks so you can rearrange what you’ve learned into new, original works.
So next time you’re tempted to copy and paste a few lines of code, I hope you’ll start typing instead.
Keep learning!
Andrew