Live data from Hacker News

Ask HN: What is your best way to learn a new programming language?

news.ycombinator.com

21–30 of 45 posts

Re: Ask HN: What is your best way to learn a new programming language?

#21
It's really pretty straight forward, I pick a simpler project from my list I'd like to do that seems like a good fit for the goals of the language, then I write it in that language.

Problems and friction are exposed pretty quickly, but you have to push through those to see if the good parts of the language make up for them. I find that if, after a short while, I don't have to force myself to write the code, and if I can dream up ways to solve any problems I encounter without turning to the documentation, then I've found a really good fit. Sometimes you find that the initial friction was largely just a matter of coming from another language's mindset.

If you find instead that you're not wanting to write code, that you're spending a lot of time fighting it or scowering the documentation or getting the build to work, then my opinion is that the language isn't worth learning anyway so it's best to move on.

Re: Ask HN: What is your best way to learn a new programming language?

#22
If you're interested in Swift just for Swift, then I would recommend against learning Swift through iOS development (just in case you were thinking about that). You'll spend more time figuring out things specific to iOS (cocoa framework, Xcode) than you will about Swift.

Re: Ask HN: What is your best way to learn a new programming language?

#23
post #19

I usually write something small that I've written multiple times before. I try to write it exactly like I would in whichever my currently most-used language is. It gets really painful in parts because languages differ. Sometimes the writing is the difficult part. Sometimes writing it in the same way is easy but the runtime performance is bad. Sometimes the tooling just doesn't support what I am trying. Finding these…

Yes, exactly what I do.

I found that using the new language as though it's the familiar one makes you quickly understand the limitations. As you try to bend the new language into supporting your own familiarisation, you accidentally learn the lower level details.

Re: Ask HN: What is your best way to learn a new programming language?

#24
All the other answers I've read so far have been good, but do not explicitly mention a key factor that has helped me learn so much.

Do your damndest to find a person more experienced with you in the language that can offer a code review after you create a mini-project or otherwise contributed to a codebase. I've learned alot on my own but having an objective person who understands the language better & can point out things like 'that thing you did in 3 lines of code can be done in 1 with this syntax in this language' has been invaluable to me.

Tap your professional network if you've got one, find a way to get this as part of your learning. I doubt you'll regret it.

Re: Ask HN: What is your best way to learn a new programming language?

#25
First thing I do is look up that language on stackoverflow. There is an info tab which is generally filled out with a ton of resources for that language, for example: https://stackoverflow.com/tags/go/info

Then I pick a simple project that will teach me both the basics and use whatever it is I'm interested in with that particular language.

Additionally, I start a new repo with code snippets. When I need to learn something I write a simple program with an example of it and maybe some variations. So I might have a file named equal.rb and compare equality with ==, eq, nils, "", etc... This helps me learn a specific aspect and later becomes my reference when I say "I know I did this before", it's a lot easier to find in my repo than find a location in a book and remember.

Re: Ask HN: What is your best way to learn a new programming language?

#26

All the other answers I've read so far have been good, but do not explicitly mention a key factor that has helped me learn so much. Do your damndest to find a person more experienced with you in the language that can offer a code review after you create a mini-project or otherwise contributed to a codebase. I've learned alot on my own but having an objective person who understands the language better & can point out…

Do you know of any website doing this? Similar to language tandems where each person brings something to the table.

Re: Ask HN: What is your best way to learn a new programming language?

#27

All the other answers I've read so far have been good, but do not explicitly mention a key factor that has helped me learn so much. Do your damndest to find a person more experienced with you in the language that can offer a code review after you create a mini-project or otherwise contributed to a codebase. I've learned alot on my own but having an objective person who understands the language better & can point out…

Do you know of any website doing this? Similar to language tandems where each person brings something to the table.

No. That sounds like an interesting idea though!

Re: Ask HN: What is your best way to learn a new programming language?

#28
start working on some problem / task that's interesting to you. Every time you encounter some aspect of the language you don't understand, or aren't confident about, write a unit test for it that tests how you _think_ it behaves. If you're right, it will pass. if wrong it will fail. modify test until it passes. Then SAVE these tests as reference for how these parts of the language work while you're learning.

Re: Ask HN: What is your best way to learn a new programming language?

#30
post #8

Read the docs, read good code, build things, stackoverflow, ship.

This is exactly what I do now minus reading the docs. I never read the original docs for anything except React. I don't know what made me do that but I remember I tried reading it but it was too big & I felt intimidated. Although, the docs nowadays are good enough & not scary like Vue, React, etc... I guess I should start reading the docs because sometimes the answer I find Googling is already present in the docs :)

I find reading the docs is the best way to truly understand a language. Reading other tutorials, books or starter manuals kind of gives you a tour of the most popular parts of the language and you have to piece them together yourself (although a good book may explain it in a more friendly way).

Perhaps it comes with experience. My first few languages were learned ad-hoc like most people learn. Only after experience with a few languages did I start reading the manuals and getting an even better understanding of them. You learn a lot even when you previously thought you were already fluent with a particular language.

I find it really helps to write a parser for the language (Assuming the language can be parsed with a LL/LALR Grammar or PEG). It doesn't need to be a robust parser which handles all errors, but just a trivial one which can help you to understand all of the edge-cases in the syntax. A parser you wrote yourself makes a good reference. Depending on the complexity of the language this can take a few hours to a few days to write.

Once you have mastered the syntax, begin to tackle the standard/common libraries bit by bit. Try to write small but useful applications to utilize particular parts of libraries. Name them well so they're easy to refer to again later, so when you come to need a particular library feature you can look up how you done it last time. (Although you'll usually look at these and be like "What the hell was I thinking back then?")

So if I were to be learning Swift, I'd grab the ePub from here: https://swift.org/documentation/#the-swift-programming-langu... and skip directly to page 917 which lists the language's context-free grammar. This is essentially a 42 page cheatsheet for the entire language syntax (could probably be condensed to about 15 pages if split into two columns and whitespace removed). This epub is a great example of well-written documentation. It's broken into groups of production rules with good cohesion, and every terminal and non-terminal symbol in the grammar is hyperlinked to the part of the document which describes it in more detail.

I'd read through the grammar and perhaps even rewrite it side-by-side as I'm going through it. (There are some good tools for writing and testing grammars interactively, which I would definitely make use of). I'd guess since the language borrows from C#, Java, Haskell et al, which I'm already familiar with, that I'll be able to understand the majority of it without looking up details - but when i do encounter something I'm not sure of it's just a click away.

Post reply on HN