Love Languages
Tags: learning, languages, programming
Published: 2020-12-12 19:39:18

## Why Every Software Developer Should Strive to be a Polyglot
 
Software development can be a challenging job with new technologies and new requirements popping up every day. It can also be a monotonous job— using the same language to solve the same problems with the same design patterns day in, day out. If you’ve been a developer long enough, it’s likely you’ve experienced both of these extremes.

Regardless of what your current responsibilities demand, one of the best ways to help you through both the rapid change and the tedious monotony is to spend time learning new programming languages. Learning a new language is exciting. It exposes you to new programming paradigms, challenges your personal preferences and go-to solutions to common problems, and improves your ability to learn new, complex systems quickly.

### The Benefits of Knowing Multiple Languages

The first and perhaps most obvious benefit is that learning a new language will provide you with the skill set needed to be productive in that language. If you’re looking for a new job, there will be more opportunities for you to consider. If you are a consultant, there will be a broader range of clients you’ll be able to support.
 
Even if you aren’t on the market for a new job, modern application development is rarely a single monolithic service written in one language. Often a single customer facing service will be composed of several microservices, all of which could potentially be written in a different language. Being able to work across several services using different languages makes you a more valuable asset to any company or team.

However choosing to learn several programming languages isn’t just about adding another language to your resume. Even if you are certain that your job will never require you to use a different language and that you will never change jobs (both highly unlikely circumstances for the average developer), you will still benefit from learning additional languages. By increasing your exposure to different language paradigms your ability to write effective, readable, and maintainable code in your primary language will increase dramatically.

Writing code in many different programming languages will give you an opportunity to view programming from new perspectives based on the unique set of priorities that define each language. It will introduce you to new problem solving techniques and design patterns and will expose the blind spots created by the inherent bias that comes from seeing programming problems from only one perspective.

As valuable as it is to have more than one language at your disposal and to improve your skills in your primary language, perhaps the most important side effect of learning several languages is that it increases your ability to learn. Learning is just like any other skill, the more you practice learning, the better you will be at it. This is especially true when it comes to learning languages. Once you have experience with three to four different languages, your ability to learn another new language increases greatly.

Not only that, learning new languages will also help you learn new architectural patterns and technologies. Many of the governing principles that make for good design in programming languages apply to other systems as well. The more interaction you have with these patterns the more you begin to recognize them in other things, and these kinds of associations will drastically increase the speed at which you learn.

![Woman biting pencil in frustration at laptop](https://dev-to-uploads.s3.amazonaws.com/i/d7ub71ismp0d0jqtxzhv.jpg)

### How to Approach Learning a New Programming Language

If you have worked with only one programming language, learning a second one may be difficult — especially if the new language has vastly different priorities, syntax, and idiomatic ways of writing code. Of those challenges, basic language syntax is generally the easiest to overcome; it is the change in thinking required to write good code in a language designed with very different underlying values and priorities that will be the greatest hurdle.

That said, the benefit of pressing through those challenges is well worth the time and frustration they cause. To start well, it’s important for you to acknowledge that you will be bringing assumptions and expectations from your primary programming language into the new one, and that this inherent bias will be a stumbling block at times. It’s not always possible to know what those assumptions and expectations will be before you begin learning, but recognizing that they exist and that they will potentially mislead you during the learning process is important. It will help you recognize their influence sooner so that you can try and adjust your thinking.

What does this look like in practice? If your primary language is C# and you are learning one of the other .NET languages, F#, your expectations and assumptions will lead you to look for try/catch blocks to express failed actions and null to communicate a value that may or may not exist because in C# both are commonly used features.

```csharp
// in C#, handling failure and dealing with values that may 
// or may not exist involves try/catch blocks and checking 
// for null
public void HandleFailure()
{
    try
    {
        var result = OperationThatMayFail();
        if (result == null)
            Console.WriteLine("value did not exist!");

        else
            DoSomethingWithResult(result);
    }
    catch (Exception)
    {
        Console.WriteLine("operation failed!");
    }
}
```

However the same approach in F#, while still producing valid code, is not idiomatic F#.

```fsharp
let handleFailure () =
    try
        let result = operationThatMayFail()
        if result = null then 
            printfn "value did not exist!"
        else
            doSomethingWithResult result
    with
        | _ -> printfn "operation failed!"
```

It is far more common for F# developers to use Option and Result types instead, both of which require changing how you think about error handling and null. As you are learning any new language, be conscientious of your underlying assumptions about correct code. Most will apply to any language, however some will hinder your progress by having you solve F# problems using C# solutions.

```fsharp
// in F#, handling failure and dealing with values that may 
// or may not exist involves matching on Result types 
// (either Ok or Error) and Option types (either Some or None)
let handleFailure () =
    match operationThatMayFail() with
    | Ok(Some(result)) -> doSomethingWithResult(result)
    | Ok(None)         -> printfn "value did not exist!"
    | _                -> printfn "operation failed!"

// or by using special functions from the Option and Result 
// modules for working with those types
let handleFailure () =
    let handleSuccess maybeValue = 
        maybeValue
        |> Option.defaultValue "value did not exist!" 
        |> doSomethingWithResult

    let handleFailure _ =
        printfn "operation failed"

    operationThatMayFail()
    |> Result.map handleSuccess
    |> Result.mapError handleFailure
```

How do you know that you are learning the idiomatic way of doing things in a new language if it’s uncharted territory? The best way is to look for experienced developers who can answer your questions either through created content like blog posts and video tutorials, through discussions either in person or through online community groups, or through public repos with well written and idiomatic example applications.

When asking another developer a question on a forum or face-to-face, try and phrase your question in a way that communicates what you are trying to do rather than how you are trying to do it. For example, instead of asking an F# developer “how do I write a try/catch block in F#?” the question can be restated as “how do I handle failed actions in F#?” The former will result in the answer you’re expecting — the correct syntax for try/catch in F# — but the latter will teach you the more idiomatic approach to handling failure in F# and will expand your error-handling tool kit as well.

![Woman in a book store staring at a wall covered in notes](https://dev-to-uploads.s3.amazonaws.com/i/q3dv87lzazspfopwgnea.jpg)

### How to Choose a New Language to Learn

With so many programming languages available, how do you decide which one to learn next? If you have an immediate need to learn a new language, that question has already been answered for you. However if you are looking to learn a new language for personal growth or to combat boredom, a key factor to consider is the diversity of language design.

If you are currently a seasoned Java developer with deep knowledge of object oriented design, consider learning a functional language that runs on the JVM like Clojure or Scala. If you are a front end developer, able to bend dynamic languages like JavaScript to your will, take a look at one of the many statically typed languages, either explicitly typed like C# and Go, or languages with excellent type inference like Haskell and Elm. Or maybe you already know several languages but they all stem from the same “C” style syntax. Consider learning a Lisp family language like Common Lisp and Scheme, or an ML family language like OCaml and F#.

Ultimately the most important thing is that you spend enough time with a new language to understand what makes it unique and how a seasoned developer in that language thinks through common problems. This does not happen overnight. If you are going to stay the course, the language you choose to learn must be one that interests you and that you enjoy.

### Love Languages

Whether you’re looking for something new to shake up your daily routine as a software developer or you’re overwhelmed by the pace of change in our industry, learning to love programming languages and consistently learning new ones may be exactly what you need to grow and thrive in your career. Focus on diversifying the types of languages you know and on retraining your mind to be adaptable to new paradigms and perspectives and you will find that not only will your software development skills grow, so too will your enjoyment of and appreciation for programming languages.