Live data from Hacker News

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

news.ycombinator.com

1–10 of 45 posts

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

#1
I know the good old answer, practice.

But are there any tricks that work for you while learning a New Language or you just get better.

I want to learn Swift as my new language so how do I approach it.

I know a lot of different languages but they have basically same syntax (C, C++, Java, JavaScript) but it takes me a lot of time to get a good grip of it and I am not sure if experienced developers feel the same or do they learn it faster.

So what's the best way to learn it and maybe the fastest?

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

#4
Yes. I usually do one or several projects to learn how a new language works. The projects I do depend on the language. I hate reading books and even moreso watching videos about a specific programming language, but thats prolly just my ADSD self.

Here's a project I'd do for Swift.

1. Write a chat server / client. (this will quickly let you see how async/threads/channels works and how good the networking libs are). You can easily go further and add a GUI to see what thats like. Add Sqlite for managing contacts/settings to see how the db layer works.

2. extract things into libraries/modules/packages i.e.whatever swift calls it, to learn how their pkg and version mgmt system works.

3. As soon as you have something working push it to a server and get it running. Add a bash script to do this automatically. The goal here is to learn how to actually release and deploy using swift.

It doesnt have to be a chat app, I usually do something thats like a problem I'm currently working on, and its best if you can actually use it to solve some real world problem. It just needs to be something that has a lot of places where you can explore parts of the language i.e. db,networking,async,etc.

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

#5
post #4

Yes. I usually do one or several projects to learn how a new language works. The projects I do depend on the language. I hate reading books and even moreso watching videos about a specific programming language, but thats prolly just my ADSD self. Here's a project I'd do for Swift. 1. Write a chat server / client. (this will quickly let you see how async/threads/channels works and how good the networking libs are). Yo…

There's nothing better than actually writing some code in the language of choice. I'm also no fan of videos on the subject. A few helpful blog posts can however be great.

My go to way of getting my feet wet is rewriting a library or a part of one I've developed before. I know the problem domain and can figure out how to tackle problems in the new language. Understanding the dependency management and publishing tooling is also always great fun!

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

#6
I had the same question when I wanted to learn C++. I was already quite practiced at Java and had written C and had read books on C++ off and on for years, but I still could not program in C++.

So I got a copy of Stroustrup "The C++ Programming Language" and started to do his exercises, but the author clearly had never done them himself, some were quite long and tedious and did not teach me anything (never put exercises in a book that you have never done), so I gave up on doing his exercises.

In my exasperation I just made up my own exercises: I just started at the beginning of the book and for each feature the book mentioned I wrote a little program that used it. The book said you can throw any kind of object, including, say, an int, so I wrote a program to throw and catch an int. I have never done that before or since, but I did it. I wrote a little program for every feature of the language. It was incredibly tedious, but it worked.

I also compiled every program with two C++ compilers and ran them and compared the difference. Many of my little programs did different things in the two compilers (!). I coded for 10 hours a day for two weeks; when I was done, I could code in C++, I could think in C++. Don't despair if it takes you longer: recall that I was already an experienced programmer.

SECRET SAUCE HERE: The key here was to actually write the program even if I was sure I had nothing to learn from it because the feature in question was so conceptually simple: you think you know something, but then when you go to actually type it in, you find out whether know it was well as you thought you did. The tiny improvements you make while doing this copy-check-repeat feedback loop is the essence of learning the skill.

Note that no mistake is too small to be worth correcting. It is critical to not say you have passed the exercise until you can produce the result exactly and reliably, as a matter of course. If you just wrote a program and it was easy, then hide it and write it again.

At one point I was embarrassed that I could not write makefiles, so instead of copying them and hacking on them, every time I needed one I wrote it from scratch; now I am a master of gnumake. I repeatedly write fizz-buzz, binary search, heapsort, hashtables, etc. over and over, just to make sure I can do it correctly and without effort.

One of Richard Feynman's wives left him, legally accusing him of spousal abuse because he did too much c1alculus: https://www.theguardian.com/science/2011/may/15/quantum-man-... '"He begins working calculus problems in his head as soon as he awakens," Bell complained to a divorce judge. "He did calculus while driving, while sitting in the living room and while lying in bed at night."'

Ben Franklin describes using this method in his autobiography of how he taught himself to write. He dropped out of second grade and ended up as one of the best writers in American history (not to mention scientist, statesman, engineer, etc.) He says he found writing he liked and practiced copying it and then checking that he had copied it correctly; see his autobiography for more.

Woz used this method to teach himself how to build computers: he had the designs of computers from Silicon Valley firms and he just practiced rote copying the designs over and over.

I tell you this as a former graduate student in Mathematics at Berkeley: The secret to learning is not reading a bunch of abstract ideas. The secret is just running a huge number of examples through your brain; your brain then abstracts them for you. There is no need to study a bunch of abstract rules. After you have learned the skill this way, doing a "master class" with an expert where you return to what you have learned and examine it, think about it, refactor it, can also be helpful. However do this after you have the skill. The standard advice in Zen practice is the same: "practice first, study later".

If you think that this cannot possibly work, then think of how you learned to speak your native language; did someone explain the rules of the grammar to you as a baby, or did you just rote imitate it? Non-native speakers of English have asked me why a feature of English is the way that it is or what the rule is for a certain situation in English. I tell them I have no idea.

Our school system lies to you completely. LEARNING A SKILL IS NOT ABOUT THE CONCEPTS, IT IS ABOUT ROTE MINDLESS IMITATION UNTIL YOUR BRAIN HAS INTERNALIZED THE IDIOMS. Your brain cannot memorize the massive amount of detail in all of the examples, so it must abstract them into idioms; once it has done that, you simply have the skill and you do not even know how you do it yourself. How exactly do you approach a door and open it? If you think you know, then please explain it to the teams of people at places like MIT who are trying to build a robot that can do that, because it is very complex. You do it and you do not even know how. But you can do it.

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

#7
Usually I’d suggest picking up a small project and shuffling between books and working on that project. Say read about the language fundamentals and then try to build up from there.

However this doesn’t really work when you’re switching to a different paradigm. When I switched to Haskell, I realized that even the way you think about things must change and diving into a project just isn’t the way to do this. You’ll keep stumbling the entire time if you bring your imperative mindset with you and attempt to leverage off them to get a quick start.

If you don’t have some functional programming experience under your belt, first spend some time familiarizing yourself with the language history and try to figure out why some design choices were made. Try and soak up as much theory as you can by getting the best books on the language. This is much slower but you have to bear in mind that sometimes you have to unlearn several things that may be considered a bad practice in the previous languages you’re familiar with.

I try to treat learning a new programming language like learning a new human language. I know quite a few and it’s always easy to fool yourself into thinking that once you know the syntax and grammar for a similar language you can port them over to the new language. You’ll be surprised to know some languages don’t have some words at all based on their culture and have no way to express something that is easy to grasp in English.

So long and short, history and some theory about the language first, then dive into a small project, pick up another book along the way and then more theory.

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

#9
Lots of different techniques.

1. Write a program in the language that I've done before just to get familiar with the tooling. My go to for years was a better Eliza clone. From 1991-2008, I wrote it in AppleSoft Basic, GW Basic,HyperCard, VMS DCL, Visual Basic, C#, PHP, and JavaScript.

2. On the job. I hate hobby side projects. I'm not creative enough to come up with anything interesting and I feel like it's a waste of my time to build something that will never get used. I would rather just work on a proof of concept related to my job after hours and show it during a lunch and learn. I get real feedback from peers and if it's implemented, I get to "productize it" and see it in the real world.

3. On the job (part 2), I'm at a point in my career, where companies will hire me if I only have half of the required experience in the technologies they use because I've worked at a lot of small companies where I've led projects either officially as a team lead or unofficially because the team was so small I could take the lead. I can usually get a job based on what I know well and they give me the opportunity to learn what I don't know while doing a project. I'm more than willing to put the time in to get familiar with a technology I don't know.

4. PluralSight - I'll watch videos to get an overview of a technology usually before I go to work in the morning while working out in my home gym.

5. Certifications - I don't believe most certifications are worth it from a career standpoint and when I'm hiring, I take many of them -especially developer certifications - as a negative signal. I wanted to learn C# in and out in 2008 when I was transitioning from 12 years of C/C++, did a combination of 1-3 and did the highest level of MS developer certification that required 6 tests. I never put the cert on my resume or talked about it during an interview, but it forced me into an organized learning path.

I'm working on my AWS certifications now for the same reason - to force me into an organized learning path. But I will put these on my resume, they seem to carry weight - especially at consulting companies.

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

#10
post #6

I had the same question when I wanted to learn C++. I was already quite practiced at Java and had written C and had read books on C++ off and on for years, but I still could not program in C++. So I got a copy of Stroustrup "The C++ Programming Language" and started to do his exercises, but the author clearly had never done them himself, some were quite long and tedious and did not teach me anything (never put exerci…

LEARNING A SKILL IS NOT ABOUT THE CONCEPTS, IT IS ABOUT ROTE MINDLESS IMITATION UNTIL YOUR BRAIN HAS INTERNALIZED THE IDIOMS.

Technology and languages change. They have definitely changed a lot since my first combination of hobby AppleSoft Basic, 65C02 assembly language programs in the mid 80s. But concepts remain. I've gotten to the point in my career where most interviews don't focus on technical minutae of the language I code in. They focus on high level architectural concepts, best practices, and leadership skills (I'm still a hands on coder but these days I'm usually either officially by title or day to day in reality an architect).

In reality, all of the popular languages in the industry are "C like". I can watch a video while I'm working out to get an overview of the language and then just start coding and know what I don't know.

Post reply on HN