Safekipedia

Programming language

Discoverer · ages 10+Adapted from Wikipedia
A man and a woman work together on an IBM 704 computer at NASA's Langley Research Center in 1957. Machines like this helped engineers do the math needed for airplane research.

A programming language is a language people design to write computer programs. It lets software be written in a way that people can read and understand. The article in the source is a Discoverer-level introduction, so it is kept at a simple reading level here.

The source code for a computer program in C. The gray lines are comments that explain the program to humans. When compiled and run, it will give the output "Hello, world!".

Before a program can run, it needs an implementation. There are two main ways to do this. In compilation, programs are translated ahead of time into machine code. In interpretation, programs are run directly. Some systems mix these two ideas, using methods such as just-in-time compilation and bytecode interpreters.

The way programming languages are designed has been strongly shaped by computer architecture. Most imperative languages were built around the common von Neumann architecture. Early programming languages were closely tied to the hardware of the computer. Modern languages often hide these hardware details through abstraction, which helps people make better software with less effort. Languages like this are called high-level languages.

Relation to natural languages

Programming languages are a bit like natural languages because both let people share ideas. Programs are usually easy for people to read and can express complex ideas, but these ideas are limited to the world of computing. The term computer language is sometimes used in place of "programming language," though some people say they are different. Some say programming languages are a part of computer languages, while others use "computer language" for a language used in computing that is not a programming language. Some think of a programming language as a plan for programming an abstract machine, and a computer language as the part that runs on a real computer with limited hardware.

John C. Reynolds says that a formal specification language is a programming language, just like any language meant to be run by a computer. He argues that some text and picture inputs that control how a computer behaves are also programming languages. He adds that many flaws in these inputs happen because people do not understand programming language ideas.

History

Main article: History of programming languages

The first programmable computers were invented during the 1940s, and the first programming languages came with them. The earliest computers were programmed in first-generation programming languages (1GLs), machine language, which was very hard to debug and was not portable between computer systems. Assembly languages (or second-generation programming languages—2GLs) were invented to make programs easier for people to understand, but they did not increase portability. At first, computer hardware was scarce and expensive, while human resources were cheaper, so languages closer to the hardware were favored. Then high-level programming languages (third-generation programming languages—3GLs) changed programming by abstracting away the details of the hardware, so that algorithms could be written in a way people understood more easily. In 1957, Fortran was invented. It is often considered the first compiled high-level programming language and has remained in use into the twenty-first century.

Two people using an IBM 704 mainframe—the first hardware to support floating-point arithmetic—in 1957. Fortran was designed for this machine.

Around 1960, the first mainframes were developed, but only professionals could operate them, and they were extremely costly. Data and instructions were entered by punch cards. After the microprocessor was invented, computers became dramatically cheaper in the 1970s, and newer languages supported more user interaction. Lisp, implemented in 1958, was the first functional programming language and dominated artificial intelligence applications for the next decades. Prolog, designed in 1972, was the first logic programming language.

During the 1980s, the invention of the personal computer changed how programming languages were used. C++, a superset of C, was introduced. In the 1990s, the rapid growth of the Internet and the World Wide Web led to new languages for web pages and networking. Java became very successful, and Python, JavaScript, PHP, and Ruby became popular scripting languages. After 2010, new languages such as Rust, Go, Swift, Zig, and Carbon appeared. Some languages, like Scratch and LabVIEW, are visual programming languages, and Blockly by Google helps developers build new visual languages. Many game engines, like Unreal and Unity, support visual scripting.

Definition

A language can be defined by its syntax (form) and semantics (meaning), and it is often defined with a formal language specification.

Parse tree of Python code with inset tokenization
Syntax highlighting is often used to aid programmers in recognizing elements of source code. The language above is Python.

Main article: Syntax (programming languages)

A programming language's surface form is its syntax. Most programming languages are textual, meaning they use words, numbers, and punctuation, much like written natural languages. Some languages are graphical and use visual relationships between symbols instead. The syntax describes which combinations of symbols form a correctly written program. It is usually described with pattern rules and grammar rules.

The meaning of a combination of symbols is called semantics. A program can be written correctly and still have no clear meaning, or it can cause an error or undefined behavior. Even a well-defined program may do something its writer did not intend. Static semantics checks rules before a program runs, such as making sure names are declared before they are used. Dynamic semantics describes how and when a program's parts should behave when it runs.

Main article: Semantics (programming languages)

Features

Main articles: Data type, Type system, and Type safety

See also: Primitive data type

See also: Concurrent computing

Main article: Exception handling

A language gives a programmer features to build software. A type system sets which kinds of data exist, the type of each expression, and how type equivalence and type compatibility work. A data type is a set of allowed values and the operations that can be done on them. Under type theory, a language is fully typed when every operation says which data it works on. An untyped language, like most assembly languages, lets any operation work on any data. In practice, few languages are fully typed, but most offer some typing. Mixing up types can give unexpected results, so type checking usually catches these type errors at compile time. With strong typing, these errors can always be found unless a variable is cast to another type on purpose. Weak typing allows automatic changes between types, called type coercion, so fewer errors get caught. Common types include integers, floating point numbers for real numbers that are not whole, and Boolean, which is true or false. A character is usually one byte, enough for all ASCII characters, and some languages use a primitive type. Storing a number too big for its type causes integer overflow. Negative numbers are often shown with twos complement, though ones complement is also used. Other types include arrays, strings, lists, associative (unordered) arrays, records, tuples, and pointers, which store memory addresses on the heap. The simplest user-defined type is an ordinal type, often called an enumeration. Since the mid-1980s, most languages also support abstract data types, where the details are hidden from the user behind an interface. This data abstraction can make code more reliable and less complex, reduce name collision, and let the data structure change without the user's code changing.

In static typing, types are decided before a program runs. Many languages require the types to be written out, but some can infer them from context. This implicit typing can let errors go unnoticed. Full type inference has mostly been linked with functional languages such as Haskell and ML. With dynamic typing, the type belongs to the value, not the variable, so one variable can hold different types. This is flexible, but it is less reliable. Some languages allow a union type that can hold any kind of value. Many languages can run several instructions at once, which is called concurrency. Languages such as Python and Ruby, which are interpreted languages, do not support using several processors at the same time. Other languages manage shared data with semaphores, a monitor, or message passing between parts of a program. Many languages also have exception handlers, which respond to runtime errors. They can stop the program and hand control to the operating system, or resume the program near the error. Handling errors well can slow a program down, so some languages, like C, skip certain checks.

Design and implementation

Computer design has strongly shaped how programming languages are built. Imperative languages, the most commonly used type, were designed to work well on von Neumann architecture, the most common type of computer architecture. In this design, the memory stores both data and instructions, and the CPU that carries out instructions is separate, so data must move back and forth. The main parts of these languages are variables, assignment, and iteration, which works better than recursion on these machines. Many languages have been made from scratch, changed to meet new needs, or combined with other languages, and many have fallen out of use. In the 1950s, people wanted one universal language for all machines and uses, but by the early 1960s this idea was rejected because different purposes needed different things. Desirable qualities of languages include readability, writability, and reliability. Early languages focused more on efficiency than readability, but readability has grown in importance since the 1970s. Having several ways to get the same result, or overloading operators so one symbol has many meanings, can make code harder to read. Keeping the number of things to learn small, called orthogonality, and using easy syntax and clear special words also help. Writing code is easier with abstraction, which hides details, and expressivity, which allows shorter programs. Most languages also come with a standard library of common functions. For reliability, Type checking, exception handling, and limited aliasing (several names pointing to the same memory) can help. Design often involves tradeoffs, such as reliability features that can slow programs down. Natural-language programming has been suggested as a way to avoid special programming languages, but this goal is still far off. Edsger W. Dijkstra believed a formal language is essential to prevent meaningless constructs, and Alan Perlis was similarly doubtful of the idea.

A language's specification is a document that users and implementors use to agree on whether a piece of source code is a valid program and what it should do. It can take several forms. It may clearly define the language's rules, written in natural language as in the C language, or in a formal semantics as in Standard ML and Scheme. It may describe how a translator for the language behaves, as in the C++ and Fortran specifications. Or it may be a reference or model implementation, sometimes written in the language being specified, such as Prolog or ANSI REXX.

Implementing a language means turning a program into machine code that the hardware can run, often with help from the operating system. The most common approach in production code is a compiler, which translates source code through an intermediate language into machine code called an executable. Compiled programs run faster than programs made with other methods. Some compilers provide optimization to reduce memory or computing use when the executable runs, though this makes compiling take longer. Another method is an interpreter, which translates each line into machine code just before it runs. This can make debugging easier, but interpreted programs run 10 to 100 times slower than compiled ones. Hybrid methods combine some benefits of both, such as just-in-time compilation, where software is compiled ahead of time into an intermediate language and then into machine code just before it runs.

Proprietary languages

Most of the most commonly used programming languages have fully open rules and tools. Many others are proprietary, which means that only one company provides the tool for using them, and that company may claim the language as its own property. These languages are often domain-specific languages or internal scripting languages for a single product. Some are used only inside a company, while others are available to outside users.

Some languages sit between proprietary and open. For example, Oracle Corporation claims proprietary rights to some parts of the Java (programming language) language. Microsoft's C# language has open versions of most of its parts, but its Common Language Runtime (CLR) is a closed environment. Many proprietary languages are still widely used, such as MATLAB, VBScript, and Wolfram Language. Some languages move from closed to open. Erlang, for example, was originally Ericsson's internal programming language. Open source programming languages are especially helpful for open science work, as they support replication and the sharing of code.

Use

Thousands of different programming languages have been created, mostly for computing, and individual software projects commonly use five or more. Programming languages need more precision than most human speech. People can make small mistakes and still be understood, but computers "do exactly what they are told to do" and cannot understand what a programmer meant. A language, a program, and its inputs must fully describe how the program behaves when it runs. To share an algorithm's ideas with people without that precision, pseudocode mixes natural language with code. A programming language gives a structured way to define data and the operations that can be done on it automatically. A programmer uses the abstractions in the language to represent ideas, built from the simplest available parts (called primitives). Programming is the process of combining these primitives to create new programs or adapt existing ones. Programs may be executed in a batch process with no human interaction, or a user may type commands in an interactive session of an interpreter. A language that runs its commands through an interpreter, such as a Unix shell or other command-line interface, without compiling, is called a scripting language.

It is difficult to say which programming language is the most widely used, because "usage" can be measured in different ways, such as programmer hours, lines of code, or CPU time. Some languages are popular for certain jobs. For example, COBOL is still strong in corporate data centers, often on large mainframes; Fortran is used in science and engineering; Ada is used in aerospace, transportation, military, real-time, and embedded applications; and C is used in embedded applications and operating systems. Popularity has been measured by counting job advertisements, books sold, lines of code, and web search references, and each method has its own bias. Stackify.com reported the ten most popular languages as Java, C, C++, Python, C#, JavaScript, VB .NET, R, PHP, and MATLAB. As of June 2024, the top five languages on the TIOBE index were Python, C++, C, Java, and C#. According to IEEE Spectrum staff, today's most popular languages may stay dominant because of how AI works, making it harder for new languages to gain popularity.

Dialects, flavors and implementations

A dialect of a programming language or a data exchange language is a small change or addition to the language that does not change its basic nature. Some languages, such as Scheme and Forth, have standards that people who build them may find not good enough, so they change the rules and create a new dialect. Other times, a dialect is made for a domain-specific language, which is often a smaller version of the language.

In the Lisp family, most languages that use basic S-expression writing and Lisp-like meaning are called Lisp dialects, even though they can be very different, such as Racket and Clojure. Because one language often has many dialects, it can be hard for a beginner to find the right guides. The BASIC language has many dialects.

Classifications

Further information: Categorical list of programming languages

Programming languages can be grouped into types, though these groups sometimes overlap. Imperative programming languages follow a sequence of ordered steps, and most of the popular languages are this type. Functional programming languages apply functions to the given inputs. Many researchers like them for their simplicity and elegance, but problems with efficiency have kept them from being widely used.

In a logic programming language, the software, rather than the programmer, decides the order in which the instructions run. Object-oriented programming (OOP) has features such as data abstraction, inheritance, and dynamic dispatch. Most popular imperative languages and some functional languages support OOP. A markup language is not a programming language by itself, but it may work together with one. Some special-purpose languages are hard to compare with other programming languages.

Quiz time!

5 questions about Programming language

Question 1 of 5

In compilation, when are programs translated into machine code?

Pictures

Technology books displayed on shelves at a bookshop in Bengaluru, India.

Keep exploring

This article is a child-friendly adaptation of the Wikipedia article on Programming language, available under CC BY-SA 4.0.

Images from Wikimedia Commons. Tap any image to view credits and license.