Blog Post: Strategies for Learning new Programming Language
Are you already comfortable with a programming language or two, and looking to expand into something new?
This article presents some tactics for teaching yourself a new language. I'll start with advice on how to approach the learning process, before offering specific tactics for you to consider. Pick the ones which best fit your learning style, and take a step toward putting them into practice.
After reading, I hope you'll take a moment to reflect on your self-learning strategy. (To avoid becoming expert beginner ๐ and to add a new tactic to your toolkit.
Prerequisites
This tutorial expects you have familiarity in at least one programming languageโenough understanding of general programming concepts that words like "string", "array", and "for-loop" feel comfortable to you.
If you're brand new to programming, you'll need to explore other articles and practice the basics.
For this article, I will offer examples in three different languages: TypeScript, Python, and bash. These are only examples, so please look beyond the languageโthese tips will work just as well for languages such as Ruby, CSS, and PostgreSQL.
The Learning Mindset
"In martial arts, when you're learning to throw a punch, it starts as the Punch."
"After practicing 1,000 times, it becomes just a punch."
When learning a new language, you're learning both syntax and technique.
Syntax is about being able to be able to write basic code without compile errors:
- writing a
print()statement - remembering the syntax of a
for-loop - reflexively knowing whether you must explicitly type-cast, or can implicitly convert, an
intinto astring)
Technique is about writing code the way most people in the community write it:
- remembering whether you need semicolons
- understating how a Python lambda is different from a TypeScript closure
- using list comprehension rather than
for-inloops - using
f-stringsto print a combination of integers and strings - knowing the meaning of "the Pythonic Way ๐
Said another way, if programming languages were like actual language:
Syntax is learning enough to talk, but everyone can hear you have an accent.
Technique is about learning verb tenses and word choices, so people never think to ask if you're a native.
W3Schools
- Python Tutorial on W3Schools ๐
- TypeScript Tutorial on W3Schools ๐
- MySQL Tutorial on W3Schools ๐
W3Schools offers bite-size tutorials for a wide collection of programming languages. After choosing your language, you can either go sequentially down the list, or pick topics that interest you. Each page has succinct examples to read and review, and, they include small quizzes to test your memory.
Beyond reading and repeating, every example can also be executed directly in your browser, allowing you to experiment with the language without installing a compiler, interpreter, or IDE.
W3Schools also utilizes gamification ๐ to encourage self-learning, letting you track your progress and earn "W3 certificates". (Who doesn't like earning gold star stickers?)
W3Schools has my endorsement as a learning tool for its gentle and guided introduction to new languages. This is the website I wish I'd known about earlier in my career.
Language-specific Documentation
Language-specific documentation can be hit-or-miss. It's worth checking out as a secondary source (with W3Schools, above, as a primary source). Don't feel discouraged if the documentation is obtuseโit could be equally likely that either you haven't acquire the necessary fluency to digest it, or that it was by great developers with mediocre technical writing skills.
Once you're committed to the language, (downloading the compiler and an IDE,) the documentation will let you dive deeper.
Consuming the documentation from the source is good for exercising your research muscle. Remember though, the documentation for some languages is better than others.
LeetCode
- LeetCode ๐ โ highly-popular, best for practicing smaller problems
- Coding Game ๐ โ semi-popular, with more competitive challenges
- Project Euler ๐ โ oft-overlooked, mathematical-focused
Websites that specialize in "coding challenges" offer a fire-hose of practice problems to cut your teeth on.
These platforms let you practice code without installing a compiler or IDE. Your code is tested exhaustively, which can train you to remember edge cases, and you can earn points for writing a solution that passes all tests. And once you've submitted a working solution, most of these sites allow you to review solutions others wrote.
Reviewing others' code offers a gold mine of learningโyou can study better solutions, and critique the poorer one, and rapidly develop technique through exposure.
The biggest challenge (pun intended) is knowing which problems to practice. There are over 900 "Easy" questions on LeetCodeโsome are trivial, while others are only "easy" if you know the trick. Some platforms offer guided courses (either free or premium), and there are many websites suggesting their own collection of "high quality" problems."
If you have the disciple to be a self-learner (and since you've read this far, you most certainly are!) then coding challenge websites are good way to apply what you've learned from tutorials and documentations.
The LeetCode Learning Trap
As an aside, problems solved != proficiency. Many aspiring developers focus on solving as many problems as possible. And while this motivation can help their "hours spent learning", they may not always mean they've learned the best solutions.
My rule of thumb is: "each problem should teach me something new"". For example, if I didn't need to learn anything to solve the problem, I'll review some of the most efficient solutions. If my solution already matches the top ones, I'll review the poorest-performing solutions to understand why they runs poorly. And if a probably is really simply, then deliberately creating the "worst" working solution can also be education.
ChatGPT โ The Responsible Way
AI assistants (like ChatGPT and Copilot) are capable of generating codeโthis isn't news. But taking a step back, the ability to immediately generate relevant examples of what you're studying is pure gold. That said, you'll need to remain critical of the examples being generated. AI assistants essentially mash together ๐ combinations of letters and characters in statistically plausible ways, and even human-reinforced learning ๐ doesn't make it foolproof.
If you're following along with this article, try the following prompts with your AI assistant of choice. If you don't have any accounts, you can experiment with the free (no registration required) Duck AI ๐ service.
- "For this conversation, only generate code sample in Python."
- (optionally) "I am familiar with the basics." โ some AI assistants will explain every line of code, so adding this will guide the assistant to only add comments about language-specific points.
Once you've primed the assistant, you can start requesting code samples. Focus on requesting generic examples, which you can then review and implement in your own project. As from my examples below, the prompts can be brief and terse. You don't even have to say "please".
- "Example of a hash table." โ "While Python doesn't have hash table, it has a dictionary..."
- "Given an array of five integers, add 1 to each element." โ don't just copy and paste the response, spend a moment reading it, and typing it into your IDE from memory
- "Sort an array of strings in alphanumeric order." โ the assistant will generate a complete example.
It's imperative that you study the examples: evaluate whether the code looks correct, understand how to reproduce it, and critique whether it's the most efficient example. Otherwise, you won't be learning how to write codeโyou'll be learning how to use ChatGPT.
Cheat sheets
- search for "python cheat sheet"
- search for "typescript cheat sheet"
- search for "mysql cheat sheet"
Cheat sheets are handy as quick reminder of a language's syntax. Having a printed version on your desk (or taped to your monitor) is often faster than alt-tabbing to a digital one.
Although I don't rely on cheat sheets as much as I used to, I still recommend them as a useful learning tactic to consider.
To Recap
Learning a new programming language has two components: syntax and technique. Syntax can be picked up passively through exposure and repetition. Technique requires critical thinking and active reflection. Learning isn't about the raw number of hours or problems solve, rather, it's about getting the most from each experience.
Before you go, pick one of the tactics above (or below) and try it right away:
- Browse the tutorials at W3Schools ๐ for a language you've curious about.
- Check out the front pages of a coding challenge website like CodinGame ๐.
- Ask Duck AI ๐ to generate a simple code example in a language you already know.