Life after JavaScript: The Benefits of Learning a 2nd Language

    Nilson Jacques

    How many programming languages do you know? According to our recent survey, around 80% of readers know at least two. Well over half of you use PHP on a regular basis, and I’d be willing to bet a significant number started web development with the language, as did I.

    Recently I decided it was time to think about adding another language to my resume (as if I didn’t have enough on my ‘to learn‘ list already). I ended up working my way through an online Scala tutorial. For anyone who isn’t familiar with it, Scala is a general purpose compiled language (like Java, it compiles to portable bytecode) with static typing. Although like JavaScript it’s a multi-paradigm language, it has a lot of advanced functional programming (FP) features found in purely functional languages like Haskell. If the recent popularity of FP has struck a chord with you, there’s much in Scala to get your teeth into.

    Silhouette of a person made from programming terms and language names

    You might be thinking “Why would I want to start learning another language now? I’m planning to work with JavaScript for the foreseeable future!” You probably also have a laundry list of JavaScript related things to learn. There are some good reasons to consider picking up a new language, though. A good way to really get to grips with concepts, such as static typing, or programming paradigms, such as FP, is to work in a language that forces you to use those things. JavaScript’s flexibility is part of its appeal for a lot of people, but it also allows you to side-step certain problems. Learning to write idiomatic code for that language will teach you different ways of looking at and approaching problems that will change the way you write JavaScript. Additionally, having the language restrict you to programming in a certain style will really help you to understand its strengths and weaknesses.

    Exposure to these new paradigms, concepts, and styles of programming can be especially useful for those of us who are self-taught and don’t have any formal training. Computer Science graduates are likely to have seen many of these ideas as part of their studies. To get the most benefit, consider studying languages that are quite different from JavaScript.

    It’s worth mentioning, too, that some currently popular libraries and patterns are based on ideas drawn from other languages. Redux, a state management library for React, is based on the data flow system in Elm. Elm itself is a transpile-to-JS language inspired by Haskell! Learning other languages can help you better understand these libraries and the concepts behind them. By staying within your JavaScript comfort zone, you’re relying on others to bring these insights from other language ecosystems and present them in a digestible way.

    Learning new languages can also affect the way you see your primary language. When I started learning Portuguese, it changed the way I looked at English. When you are confronted with different ways of doing things, it forces you to look at how those things work in your native language. Instead of taking things for granted, you start asking why things are done one way and not another. Depending on the language, you may see similarities; with Portuguese and English, some verbs are close enough for you to easily guess the meaning, thanks to their Latin origin. The same is true of programming languages, especially if you are still on your first. Exposure to other languages will help you to think about the design choices that were made when JavaScript was designed. A concrete example of this is learning a language that supports classical inheritance and being able to compare and contrast with JavaScript’s prototypal object system.

    WebAssembly (WASM), an experimental low-level language, is soon to begin shipping in browsers. Higher-level languages, such as C and C++, will be able to compile to WASM and benefit from smaller file sizes and better performance than code written in JavaScript. This will open up the browser to other languages, and you can bet it won’t be long before many of the most popular ones are able to compile to WASM. JavaScript creator Brendan Eich recently said he could foresee the possibility of JavaScript becoming obsolete at some point in the future. In all likelihood, JavaScript will continue to be important for many years to come, but having another language under your belt certainly won’t hurt your employment prospects and may help to avoid you being pigeon-holed as a JavaScript developer.

    If you really don’t have time to dedicate to learning a new language, you don’t have to stray too far from JavaScript to get some of the benefits I’ve mentioned. Last week we published the second part of our Angular 2 tutorial series, written entirely in TypeScript. TypeScript is a superset of JavaScript, so most of what you know still applies. It adds static typing and concepts like interfaces and decorators (the latter will be making its way into a future version of JavaScript). Setting aside some time to experiment with TypeScript will give an insight into the difference between statically and dynamically typed languages, and will broaden your knowledge and employability as a JavaScript developer. As the default language for Angular 2 development, job prospects are good, and the concepts you learn will make it easier to pick up a language like Java or Scala in the future.

    Can you program in a language other than JavaScript? What would you recommend as good second language for a JavaScript developer? Will WebAssembly change the game? I’d love to hear your thoughts, so leave me a comment below!