Ask HN: How did you learn a new programming language as an experienced dev?

12 points by iamandras ↗ HN
Hi folks,

I'm a JS dev and I would like to learn a new language. Probably Python or Go.

How did you learn a new programming language as an experienced dev? What was your approach?

Do you know an interactive website that explains different language features or design patterns using JS code fragments and their Python / Go equivalents?

It seems like a good approach to shorten my learning curve. Unfortunately, I didn't find a good one so far.

Thx.

23 comments

[ 5.2 ms ] story [ 62.3 ms ] thread
buy a book, any book, do all the exercises in it. after you finish that book, for any other questions you have about the language...Google

Don't make this any harder than it needs to be young buck.

Do you build a real app to practice?
I usually run through a free Codecademy course if there is one, and then follow a course or two in the target language. I'm not sure the equivalent approach might be useful, since different languages take different views of programming.
Depends on what you already know, how you learn and what documentation is available.

The three languages you mention look similar enough to not need those side-by-side examples. When you read their tutorials, you’ll probably be able to make them yourself, if needed.

For python, https://docs.python.org/3/tutorial/index.html) seems broad and deep enough to get anybody going.

For Go there is “a tour of Go” (https://go.dev/tour/welcome/1). That looks good, too.

(Aside: both may go about equivalently deep and broad into the language, but the python one chose to show you a long list of links, while the go one hid that by only showing links to the top level chapters. That’s less scary, but makes it harder to jump back to specific sections later if you want to reread them)

Once you know a language, you’ll have to learn available libraries.

1/ I pick challenges I want to solve, which are amenable to be approached through the lens of the language of choice I want to learn (e.g., a highly available app in Erlang, a system level command line utility in Rust). 2/ I source books, code bases, and papers that can inform my practice oriented learning process. 3/ Start hacking.
If you are experienced in JavaScript, switching to Python is not that hard to do. The languages' similarities outweigh their differences. I have been accused of writing Python with a heavy JavaScript accent.

The harder part of that transition is environment issues. Switching between Node environments is a solved problem. Include an .nvmrc in your project and you're done. It's very much not a solved problem in python-land.

>Do you know an interactive website that explains different language features or design patterns using JS code fragments and their Python / Go equivalents?

https://rosettacode.org/wiki/Rosetta_Code

Thanks for the link suggestion. Yeah, I've already checked several things in Python and it seems similar. I'm a bit worried about the differences in implementing different design patterns for example. So not really the basics like variables, loops, modules etc.
Not sure what your requirements are but `virtualenv` would be the standard for python environments outside of `venv` which is in the standard library. I would have considered it solved.
My approach has been always like this.

1. Shortlist a couple languages 2. Read a brief summary and some articles espousing the virtues of the langues 3. Get a sense of which feels most enticing and then pick one 4. Setup a small project with a alignment to the strengths of the language (possibly port one from a previous language) 5. Build and document the code base as you learn and leave notes in comments to various tutorials as they apply. 6. Package it up and strip out the barebones and make a simple empty shell that can be used to bootstrap future projects

Great advice. What languages did you learn so far?
I have moved between different languages over the years. But at different times I have been proficient in C, C++, JavaScript, Processing, Typescript, PHP, Python, Java/Kotlin, Matlab, R, VHDL, and a touch of swift
You can find quite a few 3h long video intros to a language on YouTube. Put that on 3x the speed to get the basic feel for the language. I've found it better than articles, since it shows the not only the language, but also the environment and workflows.
For me, project based learning is the best method for learning a new language. Basically, pick a language and build something with it. Doesn't matter what. Going this route helps you get a feel for the language, how you might actually go about building something in practice, etc., which is much more valuable information than some rando's thoughts about the language in a blog post.

Building a CHIP-8 emulator is a fun first project (and generally very approachable -- there's a C tutorial at https://austinmorlan.com/posts/chip8_emulator/, which is helpful for understanding what approach you might take to get something working in another language). For Go specifically, I learned via https://interpreterbook.com/ (and the sequel, https://compilerbook.com/).

IMO, stay away from Rosetta Code unless you're really, really stuck. You don't want to e.g. write Python in a Javascript-y way. You should learn the Python way as much as possible.

Two easy projects that I think are a good intro to any language are a tiny LISP parser/interpreter and an echo or chat server. They'll get you up to speed on internal libraries, project setup, building and testing (all the boring stuff you need to know) and then are complex enough that you can learn the core syntax and semantics with opportunities to flex the neater parts of a language.
As a JS dev learning python should be trivial. As language python is much easier. The main issue is it lacks many libraries that you are used to working with in the js world - but thats because python isnt really a web language.

All in all learning the basics should take no longer than two to three weeks, despite lower quality documentation.

One way to do it may be to pick one of the many useful node libraries and implementing them in python.

Hackerrank!

I needed to brush up on some interviewing skills and it was a nice way to focus on just the very basics of syntax. Once I was comfortable I started 'golfing' in the language on hackerrank for fun, and then I moved onto making some fun toy applications in a legit dev environment.

Don't read. Just open a laptop and code... When you hit a problem google.. Start from small problems and grow them...
I have a standard project that I do whenever I learn a new language. The reason I do the same project each time is that I already know all of the business logic, so all I need to focus on for the new project is the language and syntax, not the business logic.

My chosen project is a MUD, which is a text-based MMORPG, effectively. I already know how the TCP connections work, how to load areas/zones, how to establish characters and monsters, and how all of those things interact. So all I really need to learn is the language.

So my advice would be to pick something you've already built in the past in a language that you're vary familiar with, then port it to the new language. It's easier than coming up with something from scratch.

Your mileage may vary, but this generally works very well for me.

I really like the fact that your standard project is a MUD. Awesome!
Do you have the source code to one or more iterations of this? I was thinking of doing this, essentially with Zork!
I do a quick overview of the syntax - I check out a syntax book, cheatsheet pages or the language documentation. Then I do the "Getting started" section. After that, I try to build a project. If it's a new one, I reduce the scope to be about one or 2 days worth of tinkering and a lot of readings of documentation and other codebases.
I used "A Tour of Go"[0] which was enough having come from C/C++ and Java backgrounds. Coming from a JS background you would be missing some context about the differences between variables, data, and references/pointers. Eventually the distinction between concurrency and async might need some brushing-up on as well.

Learning Python should be much more straightforward as the way it runs is more similar to JS.

[0] https://go.dev/tour/welcome/1