HACKER Q&A
📣 wikunia

How do you learn a new programming language?


I'm currently trying to teach programming to some people by doing live streams for the public where one can ask questions and give code reviews and general mentoring (See https://opensourc.es/blog/side-mentoring/)

Would like to know how you learn a new language and what would be beneficial for you if you would have a mentor.


  👤 AnimalMuppet Accepted Answer ✓
I mainly learn from books. I learned C from K&R; I learned C++ from Stroustrup's The C++ Programming Language; I learned Perl from the Camel book. (I don't remember how I learned Java. It may have been online, or it may have been from a book.)

A mentor is useful, because after reading a book like K&R, you know how to write syntactically-correct lines of C, lines that actually do what you think they do, but you don't know how to program in C. You can write lines of C, but you don't know how to write pages of C without making a mess of it. That's where a mentor helps - that next level past syntax.


👤 dragontamer
Toy programs, especially toy-programs that demonstrate the efficacy of a particular paradigm.

A good example would be Intel TBB's "stupid Fibonacci"

https://software.intel.com/content/www/us/en/develop/documen...

This is an API, not a language, but the "lesson" is all the same. This API represents task-based parallelism as a relatively simple function call.

This "stupid Fibonacci" is very inefficient, but it demonstrates the concept. The important thing isn't about making efficient pieces of code for lessons, but good demonstrations instead.

---------

The hard part is, what constitutes a good demo program? Different people have different problems. Some are visual learners, and therefore a toy graphics program (such as the "Rosetta Smallpt": https://github.com/matt77hias/smallpt) will work out.

But some people are exceptionally poor at thinking geometrically (myself included), and looking at raytracers with cos / sin / tan functions isn't really the best way to learn a language.

---------

For me, the "best" toy programs were AIs applied to toys that I played.

I still remember when I learned recursion: it was a Towers of Hanoi solver written in Lisp. This is what "really" got it for me, because I played Towers of Hanoi as a child, and extending the thought process to an AI was just natural. I presume the modern child may know more about Sudoku, so a Sudoku solver (or a 15-puzzle) may be better.

------

I also learned Java through Robocode, a video game that was popular in the early 00s. Honestly, I probably learned more geometry from that game (trying to hit the circle-bot or wall-bot consistently) rather than through other methods. Also learned some basic AI / state machine stuff, and Java classes / interfaces / etc. etc.


👤 ekampf1
I pick a pet project to implement in that language. For example: I implemented a Twitter clone when learning Ruby on Rails, I wrote a ray tracer to learn Rust ...