Checklist For Learning A New Programming Language
A couple weeks ago, I joined Shopify as a software development intern. As tech is an inherently ever-changing industry, it means that once again I‘m being thrown into a completely new tech stack.
Since Shopify is a Rails shop, I’ve spent the last couple weeks trying to navigate my way through Shopify’s huge (and very idiomatic) Ruby codebase. After spending another late night banging my head against my desk (“why does it say my method doesn’t exist when I’ve clearly defined it here?!”), my pattern-recognition finally kicked in and I noticed that I’m running into all the same problems I ran into when I first started learning JavaScript. And Python. And C+…
I’ve decided to put together a checklist for learning a new language. The checklist is put in priority order, and is meant to quickly get someone to a point where they can actually be productive in an existing codebase in that language. I realize this goes up against some sort of consensus on how to learn within the programming community: it’s often recommended that you simply start a project and learn as you go. In my experience, however, this head-first method is doomed to have you spending too much time making language-specific mistakes and debugging common gotcha’s for really no good reason. I realize that most people will say that the best way to learn a language is to just do it (thanks Nike), but taking that as a given, this list proposes an order of learning things about the language that minimizes head-banging, while maximizing ability to get stuff done. Mostly, it’s for me to follow next time I learn a new language, so my head can finally have a healthier relationship with my desk :)
A few of caveats/disclaimers to begin:
* Most of this list is only relevant to standard imperative programming languages since they are what make up the majority of professionally-written codebases. The spectrum of programming languages is so vast, it would be unproductive to write a list to be inclusive of all, or even most languages.
* This list is meant for learning the language well enough to be productive and avoid some common pitfalls when learning a new language. It is NOT meant to be a comprehensive list!
* This list is not meant for absolute beginners to programming, but may serve as a useful roadmap nevertheless.
Please let me know if I’ve missed anything or you disagree with anything on the list! And without further ado…
0. Learn the syntax and other basics
How do I:
* Do simple math? (addition, subtracting, powers, modulo, square roots)
* Increment/Decrement an integer?
* Write and use the logical, comparison, and bitwise operators?
* Declare variables?
* Write conditionals? (if/else if /else? switch and case statements? goto?)
* Iterate over an iterable type? Over a range?
* Write a loop?
* Format a string?
* Declare the basic container types? (strings, lists, hash tables, sets)
* Declare a function/method/callable block of code?
What are the method names and basic usage syntax for:
* Strings: printing, formatting, concatenating, upcase/downcasing, sorting, splitting, substrings/slicing?
* Lists: indexing, sorting, joining, adding, removing, appending?
* Sets: union, intersection, difference?
* Hashtables: getting, setting, removing?
And, also importantly: do these actions return anything or do they just change the data structure in-place? (e.g. Python’s sort vs sorted)
Other important details:
* Are things zero-indexed or one-indexed?
* What equates to false? (null? an empty list? a negative number? Only zero?)
* Are ranges inclusive or exclusive?
Prevents: Not understanding what anyone is actually talking about, ever.
1. Understand the language’s eco-system and basic tools
An important part of working with a language is understanding the eco-system around it.
* Is there a (standard) package manager/repository for the language? (e.g. RubyGems for Ruby, pip and PyPI for Python, npm for JavaScript)
* Is there a (standard) testing framework for the language? (e.g. JUnit for Java)
* Is there a (standard) debugger for the language and how do I use it?
* Is there a (standard) version manager for the language? (e.g. RVM for Ruby, virtualenv/pyenv for Python)
* Where is the language usually used? Is it mostly used in one environment, and why?
* Are there different variants of the language?
Prevents: Being thoroughly confused when your friend tells you about PyPy’s Just-In-Time compiler, because you’ve only heard of PyPI, and you don’t get how a packaging index can have a JIT compiler.
2. Understand the language’s philosophy & conventions
* Is there a zen/philosophy for the language? What is it?
* What are some common idioms in the language that fall out of the philosophy?
* What is the conventional way to name a function/class/constant?
Prevents: Being that person who iterates over Ruby lists using C-like for-loops. Ew, haven’t you ever heard of ‘each’? Ugh, make another pull request once you’ve fixed this disgusting mess.
3. Look up common “gotcha’s!” ahead of time
The basis for writing this post was to avoid head-banging when learning a new language, so it of course makes sense to find out what made other people bang their heads when they learned the language.
Prevents: Banging your head with frustration when all that grief could have just been avoided. Learn from others’ mistakes!
4. Understand scoping and namespaces
* How are things scoped? Is there block scoping? File scoping (e.g. C++)? Function Scoping (e.g. JavaScript)? Module scoping (e.g. Python)?
* Is there a global scope? If so, how do I access/change global variables?
* How are namespaces provided? How do I include/use things defined in namespace X?
Prevents: Not being able to answer the question “If I declare ‘x’ here, will it exist when my program reaches location ‘y’ in the code?” and then being confused when your stuff stops existing.
For more on scoping: https://en.wikipedia.org/wiki/Scope_(computer_science)
5. Understand methods/functions and how arguments are passed to them
Most modern languages pass primitive types by value, but…
* By default, does the language pass class types by reference? Value? Something else completely?
To add,
* Can I overload methods/Can I define optional arguments to methods?
* Can I define default values for the parameters to my methods?
Prevents: Thinking your helper method returns a modified version of your Python list when actually you’ve changed the original list and every variable assigned to that list now also holds the modified version and oh god what is happening?!
Also prevents: Creating methods “DoThis”, “DoThisV2”, and “DoThisV3” because you architected your code thinking you could overload methods, but actually you can’t, and you were updating a public interface, so now you can’t change “DoThis” without breaking everyone’s code.
6. Understand how classes, objects, and inheritance work
Of course, this is only applicable if the language supports OOP.
* Is there a concept of private / public / protected etc in the language?
* How does an object refer to itself? (‘this’? ‘self’? other?) Does it need to explicitly refer to itself?
* How does an object refer to its class?
* How do I declare and use class variables? Instance variables?
* What does inheritance look like and how does it work?
* Does a subclass inherit all of the superclass’ attributes, even the class attributes?
* Is there multiple inheritance, or no?
* Does the language make use of mixins?
* Is there explicit support for interfaces and abstract classes? Either way, what does it look like when you implement one in the language?
Note: If the language is a Prototyped-base language (e.g. JavaScript) or otherwise, then one would want to instead understand how prototypes work and so forth.
Prevents: Why can’t I access this attribute? Why does it tell me this method doesn’t exist when it exists in the superclass? What is this weird file where all the methods are empty? Oh my god does self refer to the object itself or the objects’ class?!
7. Learn how to do some common tasks, and get to know some libraries while you’re at it
These tasks are extremely common, and generally make some use of the standard library of the language. Or, they make use of external libraries that are so commonly used, they may as well be part of the standard library (e.g. requests for Python).
How do I…
* Traverse a filesystem?
* Read from / write to files?
* Parse JSON/XML/CSV/some other standard format?
* Apply regular expressions?
* Send HTTP requests?
* Correctly use Unicode?
Prevents: …Not being able to do these things? Or even worse, re-inventing the wheel to do them.
8. Look up language’s quirks & other fun details
At this point, you should be able to navigate a codebase in your new language well enough. You should also be able to write code with less head-banging. However, there’s always more to learn!
Some fun things to explore…
* Does the language support a functional way to program? (Are functions first-class citizens? Do I have access to map/filter/reduce methods?)
* If the language isn’t duck/dynamically typed, how does it handle generics/templating?
* How is memory managed? Is there garbage collection? How does it work?
* What are the actual time complexities of standard methods on common data structures?
* How does this language shoot itself in the foot?
And of course, every language will have quirks that will please, flabbergast, surprise, and/or disgust you.
9. Don’t stop!
In summary, from my admittedly short time writing code (and even shorter time doing it professionally), these are the things that — if I had taught myself in the first week of learning a language — would have saved me a bunch of time.
Of course, knowing all these things is just a small step on the road to mastery. Never stop!
Have any suggestions/critiques? Let me know @larissafeng.