Learning a new programming language

written on in Learning and Programming

Learning a new programming language broadens your mindset, it lets you tackle new or known problems differently and is actually a lot of fun. I want to share some tips that helped me choose a language, get going and also stick with it.

The "Pragmatic Programmers", Andy Hunt and David Thomas recommended in 1999 to learn a new programming language every year (which they did - they wrote the first book about Ruby in English language) and Chad Fowler also notes in The Passionate Programmer that your job opportunities may increase by diversifying your programming languages, even if you won't use them in your new day job. Paul Graham calls this the Python paradox. So I'm trying to convince you in the following paragraphs.

Where to start?

A good starting point for choosing/browsing for a new language is looking what others think:

Choose wisely and pragmatically

It may be tempting to peak at something very exotic, however stay pragmatic: Learn something you actually want to use, and moreover, you should have a concrete (pet) project in mind. Every language excels in some areas which you should be aware of (e.g. web programming, text processing, embedded systems, system administration etc.). Some languages also have some outstanding libraries or frameworks that may be of interest to you (e.g. Ruby on Rails, boost C++ Libraries, or SciPy). Your instincts will lead you to the right choice if you're honest with yourself. If the languages bore you to tears then your interest will quickly disappear. So don't choose a language solely because it's special (What Killed Smalltalk Could Kill Ruby, Too) but rather choose a language because it seems to be fun and the right tool for your project!

It's worth the effort - even if you abandon your chosen language you have nevertheless:

  • acquired a basic understanding of the language, or better yet, the distinct idiomatic patterns which could help you in the future anyway.
  • developed the ability to read the language's syntax which helps if you migrate stuff
  • gained knowledge that this language (or a popular module/lib/jar/gem/package of it) excels in a certain domain.
  • gained knowledge about some facets (syntax, purpose, paradigm etc.) you dislike or like
  • or even better, you know what you would like to learn instead.

Write and read lots of code

Similar to learning a new foreign language the best way to actually learn something is by doing it. Well, duh! So don't just read about your new programming language, instead read as much code as you can and also write your own. Reading foreign code is very important, because you will quickly assimilate different patterns and idioms and get some experience with use cases of particular libraries. It has never been easier to get in touch with source code in times of Git, Mercurial and SVN. Furthermore, the popular code hosting websites support code browsing, i.e. you don't even have to actually download anything to peak into a project.

Aside: Grady Booch recently said in an interview that he doesn't understand why every engineering course studies the masterpieces of their guild and only in computer science everybody starts coding (and learning) from scratch.

Sources:

Stay tuned through blogs (feeds) / mailinglists

Through the official feed aggregator of your new (soon favourite) language, you get a feeling of the actual issues and discussions going on. You get an overview of the language usage and the people using it. I'm more the feed-guy but if you like mailinglists, go right ahead. Get to know the topics and the important people. Does their mindset fit yours? Are the ongoing language improvements already solved in you current programming language? What problems of your current language don't exist in this new programming language and more importantly ask yourself why?

Dive deeper with books or magazines

With the O'Reilly Pocket Guides you can start smart (start s-mart ;). This are ideal if you only have a short period of time to check it out but they're more of a pocket references than a comprehensive language introduction.

In general I value books more, because most books are most of the time well thought-out and cover a lot of ground. But books also have their pitfalls: The ravages of time. Always watch out for an up-to-date book and you should also check the author first. If the author is one of the core team, then go ahead and buy it. I would advise you to buy books written in English rather than in your native language because the information is fresher, and moreover, you're also improving your English skills which are indispensable.

Magazines are great to wet your appetite but in my opinion it stops there. Nowadays I'm much happier with (good) feeds which can fulfill the same purpose.

Take your time

In my opinion if you learn a programming language properly it will stay with you forever. If you just want to take a short ride and grok the basics that's okay, but if you really want to augment your toolbox then you will have to be disciplined and put the required effort in. It's fun to visit a different country and practice some sentences in the foreign language when on holiday but to become a fluent speaker, you need to move there sooner or later in order to speak the language every day. Try especially to assimilate the idioms of a language, and don't write code which looks foreign. In the case of Python Martijn Faassen illustrates this well in his code example in What is Pythonic? and Phillip J. Eby shows why each language requires a different mindset in Python is not Java.

Seek community

Watch out! Not only for Spiderman, but also for local user groups, conferences or programming buddies. These sources allow you to get new ideas, gather feedback on your "superior" new language, ask questions or just provide you with the opportunity to meet interesting people. Remember that the talks are likely to be video-tapped so the really important point is to get in touch with some people you won't meet ever or soon again. Maybe he or she can recommend you another conference where you both can meet again.

Strive for diversification

Try a language with a paradigm you aren't familiar with: Learn a functional, object-oriented, dynamically typed or even a Markup (HTML5) or Domain Specific Language (CSS, SQL, XPath, Regular Expressions). If you are a backend guy, have a look at the frontend or the other way around. Learn something hot or very specific, or just ubiquitous (e.g. Java, .NET).

There are three types of diversification strategies in marketing lingo we can borrow:

  • Concentric diversification → Augmenting your knowledge by adopting more parts of the stack, tiers or layers (think OSI model or web stack):
    • You already know HTML, CSS and now you want to learn the missing piece which is JavaScript
    • You are already comfortable with the server side and now you want to tackle the client side
  • Horizontal diversification → Staying in your current business by studying alternatives or drop-in replacements:
    • You already know Java now you want to learn Ruby
    • You already know Oracle now you want to deal with PostregeSQL
  • Conglomerate diversification (or lateral diversification) → Learning a new technology which isn't related to what you've done before:
    • You already know web related stuff but now you're going to learn building desktop apps
    • You already know developing embedded systems but now you are interested in data analysis.

Wrapping it up

Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages

If already know all of this, that's great, because then there's no excuse left! Warning: You won't be able to learn something without sacrifice. It may be time consuming in the beginning but it could be that the new language thrills you so much, that you will neglect some of your older pets, which aren't that interesting any more (which is generally a good thing).

One last piece of advice: If you can't decide, or you need more insight, then the recently released book Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages by Bruce A. Tate could be your answer: "You’ll get a hands-on tour of Clojure, Haskell, Io, Prolog, Scala, Erlang, and Ruby".