Why are there so many programming languages?
That's a lot like asking "Why are there so many fields of mathematics? We have algebra. Why do we need geometry, calculus, and fluid mechanics?" Every programming language aims to solve a particular problem. More than one language might be able to solve the same problem, but each will approach it differently.
Here are some of the major differences in programming languages.
Legibility and maintainability
Some languages are easier for a human being to read, which makes it easier for one programmer to collaborate on another programmer's code. Python, for example, has a reputation for being easy to read. It enforces strict indentation of lines to define its code blocks, which makes it easy to glance at a program and figure out its structure. Other languages allow indentation as well, but as a stylistic choice, not as a requirement.
In contrast, Perl is a language that allows the programmer to write the same program in many different ways. Still, the program's purpose might not be immediately clear to another reader. Such a program may be convenient to write, but difficult for someone else to understand and edit.
Some languages are interpreted, and some are compiled. A compiled program must be processed by a preprocessor, compiler, and linker before it can be executed by the computer. This specialized intermediate software performs lexical analysis, translating the program into machine language. It may also optimize the resulting instructions, looking for clever ways to make the program run faster.
Compiled programs usually perform better than interpreted programs. For instance, C, C++, and Objective-C are languages that compile to very fast machine code. Video games and system software are often written in these languages, to squeeze every bit of performance out of the CPU.
On the other hand, interpreted-language programs are run by software called an interpreter, which executes the program's instructions without first compiling them to machine code. Although the interpreter sometimes parses the program to an intermediate language, resulting in some optimization, the performance is never as fast as compiled machine code.
Specific use cases
Often, languages are especially good at writing specific types of programs. For instance, NodeJS is designed to write single-threaded applications for the web. Its non-blocking file I/O permits programs to continue operating ("not be blocked") while they wait for required data to transmit.
Another example is the R programming language, which specializes in statistical analysis. Programs written in R benefit from built-in analytical tests and models, and tools to efficiently manipulate massive quantities of data.
Ease of prototyping
Some languages allow for rapid prototyping: the programmer can "start writing," and build component upon component until the program is fully formed.
For example, the website Reddit was originally written in Lisp. After Reddit launched, the entire site was rewritten in Python for many reasons, both technical, and logistical. Although refactoring all the code was a major undertaking, the site's owners expressed no regrets. In a 2005 blog post, they remarked that Lisp allowed them to create something without knowing exactly what it would become.
Usually, when you start a new programming project, you don't want to re-invent the wheel. That is, you don't want to write functions for common tasks like calculating a square root, or finding the first occurrence of a character in a string. For this reason, nearly every programming language provides a set of standard libraries of common functions. Programmers may prefer a language because of the libraries it provides.
For instance, the C standard libraries provide highly performant functions for many low-level system operations. Perl provides many robust libraries, and also the CPAN repository of modules to be downloaded and used in your program. Python provides a wide array of built-in functions and modules for almost everything under the sun. Clojure, a Lisp-like language that runs on the JVM, benefits from its ability to run code from the extensive existing libraries of Java objects and methods.
Not all languages lend themselves to writing safe code. The C programming language, for example, is notorious for having features (or lack thereof) that lead to devastating vulnerabilities such as null pointer dereferencing. Other languages try to address these concerns with stricter rules.
For instance, some languages place restrictions on what operations can be performed on various types of data. The strictest of these languages are sometimes called "strongly typed," and they can offer peace of mind to programmers who prioritize security and stability in software development. Examples of strongly-typed languages include Rust, Nim, Ocaml, and Haskell.
Languages may also place limits on "mutability," the ability of a data object to change state. Instead of objects whose values are overwritten, these languages favor "immutable" objects: values in memory that cannot be changed without explicit exception. Immutable objects have attracted interest as multi-core CPUs have become widespread, because of their tendency to promote "thread safety." In a thread-safe program, more than one processor may operate on one set of data with a greatly-reduced risk of error. Languages that prioritize immutable objects include Rust and Clojure.
When programming in a new language, it helps to access an active, passionate community of developers who actively use and contribute to each other's work. Before choosing a programming language, find out more about that language's community. Some languages have an exciting, dynamic, vibrant user base you might want to be part of and other languages may have little or no community.
When writing a program, the programmer's thoughts and problem-solving abilities are "speaking" through that language. As a result, programmers tend to prefer languages where they are comfortable expressing themselves. What makes a language and programmer work well together is hard to define, however. Ultimately, the only way to know which language you are comfortable with is to use different languages for different projects and compare them for yourself.
- How can I learn more about computers?
- Links to where to watch free online lectures and courses.
- All computer learning and training pages.
- See our programming languages page for an index of programming languages.
- See the programming terms for a full list of computer programming-related terms.
- Software help and support.