How I Learn A New Programming Language
Recently I received an invitation on LinkedIn as a selected “expert” to write up the best way to learn a new programming language. It’s a good topic so I figured I’d go ahead and cover it here.
Get It In Your Brain
When I learned Rust, the recommended approach was to read through the book once as quickly as possible to get the entire overview into your brain. I was happy to see this advice, because I have been doing this for many years. Back in the 1980’s my dad photocopied the IBM BASIC manual, had it bound in 4 or 5 volumes, and put it on my desk to read. The stack of books was intimidating. I started reading and quit. I couldn’t understand half of it. My dad said, “Read it and don’t try to understand. You will remember it when you need to.” Over the years I have learned to trust the capability of the mind to comprehend things beyond our conscious understanding. But it can’t remember something if you haven’t read or heard it.
Type Out the Examples
The next step is to slow down and attempt to understand the concepts. Find a good book, and go through it one chapter per day. To move beyond the academic and into the practical, type in each example and run it. Try playing around with the examples, changing values to really grasp what is being illustrated by the example. For me, this generally, takes a month, and can take anywhere between 30 – 100 hours.
Learn the Culture
When I learned Java, my mentor told me, “If you haven’t read Effective Java, you aren’t really a Java developer.” I followed his example and read, and re-read Effective Java every year for close to a decade. It introduced me to the concept of idioms in programming. Beyond simple syntax difference, every language is designed with a certain development philosophy. You can’t program Java the way you would C++, or Python the way you would Java, or for that matter Rust like any other language. I always start out learning a new language by searching for the “Effective Java” for that language. They usually start with “Effective”, like “Effective C,” “Effective C++,” “Effective Python,” etc.
Beyond syntax and idioms, there is also culture. This can take much longer to absorb and assimilate. Typically a community grows around a language and acceptable patterns and practices emerge. What is perfectly acceptable in one language could be an egregious “sin” in another. I have found, for example, the Rust community is extremely harsh about the “right and wrong” ways to program in Rust.
Practice, Practice, Practice
You can’t learn a programming language without programming in it. I have a “playground” project which contains reproductions of all the coding tests I’ve taken throughout my career, all the way back to Fizz Buzz. I rewrite my “playground” in each new language I learn, copying the style, idioms, and culture to the best of my ability. Recently I have been writing Lox from “Crafting Interpreters” in each new language. Between the code and unit tests this typically comes up to around 5 – 7K lines of code.
Summary
When I learned Rust, I read “The Rust Programming Language” in 2 days. Then, I spent 3 weeks walking through the book chapter-by-chapter, running each code example. Then I translated my “playground” to Rust. Then I wrote 5,000 lines of Rust, converting the Lox tree-walk interpreter. Well, at least till I got stuck on Environments, and realized I didn’t understand Rust’s memory management and lifecycles as well as I thought I did. So, I read the book again, and rewrote Lox using smart pointers. Final step, add “Rust” to resume… as beginner 🙂
Leave a Reply