Learning a new programming language efficiently

How your existing knowledge helps and sometimes hinders when you learn another language, with a practical plan to become productive quickly.

· Updated

Most developers learn several programming languages during their careers. The second or third language is usually faster to learn than the first, but it is not always as easy as expected. This article explains why your existing knowledge can both help and cause problems, and gives a practical plan for learning a new language.

What you bring with you

When we learn something new, we use what we already know. Psychologists call this transfer. Transfer can help, when old knowledge makes new learning easier, or it can cause problems, when old habits lead to mistakes.

Both happen when developers learn a new language. Scholtz and Wiedenbeck (1990) watched experienced programmers write code in a language they did not know. The programmers used plans and habits from languages they already knew. This helped them solve problems, but it also led them to write code that did not suit the new language.

A later study looked at questions on Stack Overflow and interviewed professional developers (Shrestha et al., 2020). It found that many difficulties came from wrong assumptions carried over from a previous language, for example about how variables, types or memory work.

What carries over and what does not

It helps to think about your knowledge in three layers.

LayerExamplesCarries over?
General ideasVariables, loops, functions, data structures, algorithmsYes
Language featuresTypes, memory, error handling, concurrencyPartly; check carefully
Habits and toolsNaming style, standard library, package manager, test toolsRarely

The first layer is your main advantage as an experienced learner. The second layer is where most mistakes happen, because features with the same name can work differently. For example, the meaning of =, == or null varies a lot between languages. The third layer usually has to be learned almost from the start.

A practical plan

1. Learn the differences, not the basics

You do not need a full beginner course. A better start is a guide written for people coming from another language, or the official language tour. Focus on what is different: the type system, memory, error handling and how code is organised.

2. Write small programs on the first day

Reading about a language helps you recognise it, but not use it. On the first day, write and run small programs: read a file, process some input, call a web API. Each small program makes you use the tools and the standard library.

First steps in a new language
# Create a project and run its tests before writing any real feature
cargo new hello && cd hello && cargo test      # Rust
go mod init example.com/hello && go test ./... # Go

3. Learn how the community writes code

Code that works is not always code that looks natural in that language. Read well-known open-source projects and compare their style with yours. Most modern languages have linters and formatters, and their warnings also teach you the common style.

4. Build one realistic project

After a week or two, choose a small but complete project, similar to something you have already built in another language. Because you already understand the problem, you can focus on the language itself.

5. Ask for feedback

Someone experienced in the language can quickly spot habits you have brought from other languages. If no colleague is available, online communities and code review sites can help.

Warning

Be especially careful with features that look familiar. Similar-looking code can behave differently, and these differences often cause bugs that are hard to find.

Conclusion

Your experience makes a new language easier to learn, but only for the knowledge that really carries over. Focus on what is different, write code from the first day, learn how the community writes code and ask for feedback. In this way you can become productive quickly while avoiding the mistakes that come from false familiarity.

References

  • Scholtz, J. and Wiedenbeck, S. (1990). Learning second and subsequent programming languages: a problem of transfer. International Journal of Human–Computer Interaction, 2(1), 51–72.
  • Shrestha, N., Botta, C., Barik, T. and Parnin, C. (2020). Here we go again: why is it difficult for developers to learn another programming language? Proceedings of the 42nd International Conference on Software Engineering, 691–701.

Next steps