Cyrus Stoller home about consulting

Analogies to understand programming languages

Many non-techies have a hard time understanding why there are so many programming languages. In this post, I hope to show you that the tradeoffs between programming langauges are similar to differences between natural languages. Hopefully these analogies will make the differences more accessible.

Transportation

A Prius can nimbly get you from point A to point B, but it won’t be effective at hauling heavy machinery. When you’re working at an industrial scale, you need more powerful vehicles like tow trucks or 18-wheelers. Personal vehicles and professional vehicles aren’t substitutes.

The same is true for programming languages. Higher level scripting languages like Ruby and Python work well for everyday projects, but as elements of an application face more stringent performance requirements, it’s often better to translate code to lower level languages like C/C++. But, it’s all relative. Before interpreted languages were commonplace, C/C++ was considered a higher level language when compared to assembly and machine language.

Taking this analogy one step further, higher level languages are like driving an automatic transmission, while lower level languages are like driving manual. If you’re running errands, an automatic will suffice, but if you want to maximize control, you’d insist on driving manual.

Language families

Like natural languages, some programming languages are closely related. Because Romance languages have a shared heritage, Italians can understand a lot of Spanish, even if they can’t speak it themselves. Similarly, Pythonistas can read and debug Ruby with relative ease even if they aren’t familiar with common idioms. Reading Ruby written by a Pythonista would be like listening to someone speak with an accent. While technically correct, they’d likely use phrases that seem a little odd.

Alphabets and syntax

In the same way that there are lots of alphabets to express natural languages, there are different syntax structures to express programming languages. Even though Chinese and Japanese share Kanji, they are grammatically different and share no pronounciation. Others like Urdu and Arabic use similar alphabets and pronounciation, but are different languages.

Some typical syntax structures include:

While there are minor differences between syntaxes, you’ll be able to make out what’s going on in the same way that as an English speaker you’d be able to make out words in Spanish even though there’s the addition of the ñ. Think about syntax differences between programming languages like alphabet differences between natural languages.

Similar sounding names

Just because programming languages have similar names doesn’t mean that they’re related to each other. Many people mistakenly believe that JavaScript is a derivative of Java, when in reality they come from different language families. JavaScript was designed as a functional programming language, while Java is strictly object-oriented programming language. Similarly, Telugu and Tagalog may have similar sounding names but originate from India and the Phillipines respectively and are unrelated.

Types of ideas

Like natural languages, programming languages shape the kinds of ideas that you think about. For example, Farsi doesn’t have different words for lime and lemon لیموترش and words like saudade in Portuguese and hygge in Danish have no real translations.

There are many programming paradigms, each providing a preferred set of tools to solve a problem. As a result, imperative programming, functional programming, and object-oriented programming each encourage programmers to solve problems in different ways. One noticeable difference is the concept of immutability.

Conclusion

Just because a given vehicle has four wheels, doesn’t mean that it’s the right car for the job. The same is true for programming languages. Just because a language is Turing Complete, and can techincally express any program, doesn’t mean that you should use it for everything. Some languages are better designed for certain tasks. You don’t always need to use the most performant language. Going to the grocery store doesn’t require a racecar.

The key take away is that there isn’t a one size fits all. Use the best language for the job.

Some recommendations (just my opinion):

Category Advice