langwhy

The basics

Why there are so many programming languages, and why you can't use one for everything. No programming knowledge needed.

Every language is a deal

A processor only follows tiny instructions: add two numbers, copy this, jump there. Nobody writes those by hand anymore. People write code in a programming language, and another program turns it into instructions the processor can follow. Each language decides how that happens, and every decision gives you something and takes something away. No language wins every decision, so people keep making new ones for the jobs the old ones handle badly. PLDB, a public database of languages, lists more than 3,400 programming languages.

Think of an online shop. The page you click on runs JavaScript in your browser. The server behind it might run Go or Python. The orders sit in a database you ask questions in SQL. Three places, three languages, because each place wants something different. This site calls those places slots, and every language card says how well the language fills each of the 13.

How the code gets run

There are three common ways, and they decide speed and convenience.

TypeScript takes a fourth road: it is translated into JavaScript, which the browser then runs.

Who cleans up memory

A running program keeps borrowing memory and has to give it back, or the computer runs out. The Rust book sums up the three classic answers: some languages have garbage collection that looks for memory no longer in use while the program runs, in others the programmer frees memory by hand, and Rust uses ownership rules that the compiler checks.

Checked before or while running

Every value has a kind: a number, a piece of text, a list. A language with static types checks that kinds match before the program runs; TypeScript calls itself a static type checker for this reason. A language with dynamic types checks while the program runs, so writing is quicker and some mistakes show up only when that line runs. Python allows type hints, but no type checking happens at runtime; a separate tool checks them.

Doing many things at once

A web server may talk to ten thousand visitors at the same moment. Languages handle that in different ways: threads managed by the operating system (Java, C++), lighter threads managed by the language itself, such as Go’s goroutines, async code that starts slow work and moves on until it finishes (JavaScript), or small isolated workers that only send each other messages, like Elixir’s processes.

So why can’t one language do everything?

Because of those deals, and because every place where code runs has its own rules. A language tuned to be quick to write pays for it in speed. A language that gives exact control over memory makes mistakes easier. A browser accepts only JavaScript and WebAssembly. When a language does not fit a slot, its card names one of the seven reasons below.

1. It doesn't run there

Every place where code runs decides which languages it understands. A web browser runs JavaScript and WebAssembly, so a Python or Ruby program cannot run in a web page unless it is translated first or ships a whole interpreter along with it. Phone makers choose the tools for their phones: Apple builds its app tools around Swift, and Google recommends Kotlin for Android. A database engine takes SQL. When the place does not speak the language, you translate the code, carry an interpreter with you, or pick the language the place speaks.

Sources: developer.mozilla.org, developer.apple.com, developer.android.com, postgresql.org

2. Too slow or too heavy

Some languages are run by another program, an interpreter or a virtual machine, instead of being turned into machine code ahead of time. That makes them easier to write and to move between computers, but every step in between costs time and memory. For a script that runs once, nobody notices. For a game that has to draw a new picture 60 times a second, a cheap device with little memory, or a server answering thousands of requests, the extra cost decides. Python adds one more limit: its global interpreter lock lets only one thread run Python code at a time.

Sources: developer.mozilla.org, peps.python.org

3. It hides the machine

Many languages clean up memory automatically with a garbage collector. You never free memory by hand, and a whole family of bugs disappears. The price is control: the collector decides when it runs, it needs memory of its own, and the program cannot reach an exact spot in the hardware. An operating system, a device driver or a chip with a few kilobytes of memory needs that control. That is why the Linux kernel is written in C and also accepts Rust, two languages without a garbage collector.

Sources: go.dev, docs.kernel.org

4. Too easy to get dangerously wrong

In C and C++ the programmer manages memory by hand. Forget to check a length, or use memory after giving it back, and the program may crash or let an attacker take it over. The compiler does not catch these mistakes. The Chromium team at Google found that around 70 % of their serious security bugs are memory safety problems. That is why new code that faces the internet moves to languages that check memory for you: on Android, memory safety vulnerabilities dropped as new code was written in such languages.

Sources: chromium.org, security.googleblog.com

5. Nobody built the tools

A language is only part of the work. The rest is libraries other people already wrote: code that reads images, talks to a database, trains a neural network or draws a button. Machine learning happens in Python because PyTorch and NumPy are there, not because Python is fast. Android apps are built with the tools Google provides for Kotlin and Java. Another language could in principle do the same work, but you would have to build the missing pieces yourself and find people who know them.

Sources: pytorch.org, numpy.org, developer.android.com

6. Built for one kind of job

Some languages are made for one task and do it well. SQL asks a database questions about its data, but it cannot draw a window or serve a web page on its own. Bash starts other programs and connects them, but it has few ways to structure data or handle errors, so long Bash scripts get hard to keep correct. Google's style guide says a shell script longer than 100 lines should be rewritten in a more structured language.

Sources: postgresql.org, google.github.io

7. More than the job needs

Sometimes a language can do the job but asks more than the job is worth: a compile step, a project to set up, or a page of code where another language needs three lines. Renaming a folder of files is a few lines of Bash or Python; in C++ it needs a project, a compiler and a build. Java's designers call this ceremony, and in Java 25 they made small programs shorter to write so that beginners and script writers face less of it.

Sources: openjdk.org, google.github.io

Words you will meet

Dotted words on this site link to the glossary, which explains each one in a sentence or two. Language names link to their cards.