A programming paradigm is a relatively high-level way to conceptualize and structure the implementation of a computer program. A programming language can be classified as supporting one or many paradigms.
Paradigms are separated along and described by different
dimensions of programming. Some paradigms are about implications of the execution model, such as allowing side effects,
or whether the sequence of operations is defined by the execution
model. Other paradigms are about the way code is organized, such as
grouping into units that include both state and behavior. Yet others are
about syntax and grammar.
object-oriented – organized as objects
that contain both data structure and associated behavior, uses data
structures consisting of data fields and methods together with their
interactions (objects) to design programs
Object-based - paradigm in which the object has a construct to encapsulate state and behavior, but without inheritance or subtyping
Prototype-based – object-oriented programming that avoids classes and implements inheritance via cloning of instances
Data, Context, and Interaction
- paradigm that emphasizes mental models and run-time behavior of
networks of objects, whose responsibilities are granted dynamically
based on roles they play in interactions with other objects
Declarative
– code declares properties of the desired result, but not how to
compute it, describes what computation should perform, without
specifying detailed state changes
functional
– a desired result is declared as the value of a series of function
evaluations, uses evaluation of mathematical functions and avoids state
and mutable data
logic
– a desired result is declared as the answer to a question about a
system of facts and rules, uses explicit mathematical logic for
programming
reactive – a desired result is declared with data streams and the propagation of change
Concurrent programming
– has language constructs for concurrency, these may involve
multi-threading, support for distributed computing, message passing,
shared resources (including shared memory), or futures
Actor programming – concurrent computation with actors that make local decisions in response to the environment (capable of selfish or competitive behaviour)
Constraint programming
– relations between variables are expressed as constraints (or
constraint networks), directing allowable solutions (uses constraint
satisfaction or simplex algorithm)
Distributed programming – has support for multiple autonomous computers that communicate via computer networks
Generic programming
– uses algorithms written in terms of to-be-specified-later types that
are then instantiated as needed for specific types provided as
parameters
Metaprogramming
– writing programs that write or manipulate other programs (or
themselves) as their data, or that do part of the work at compile time
that would otherwise be done at runtime
Template metaprogramming
– metaprogramming methods in which a compiler uses templates to
generate temporary source code, which is merged by the compiler with the
rest of the source code and then compiled
Reflective programming – metaprogramming methods in which a program modifies or extends itself
Pipeline programming – a simple syntax change to add syntax to nest function calls to language originally designed with none
Rule-based programming
– a network of rules of thumb that comprise a knowledge base and can be
used for expert systems and problem deduction & resolution
Visual programming – manipulating program elements graphically rather than by specifying them textually (e.g. Simulink); also termed diagrammatic programming
Overview
Overview of the various programming paradigms according to Peter Van Roy
Programming paradigms come from computer scienceresearch into existing practices of software development.
The findings allow for describing and comparing programming practices
and the languages used to code programs. For perspective, other fields
of research study
software engineeringprocesses and describe various methodologies to describe and compare them.
A programming language can be described in terms of paradigms. Some languages support only one paradigm. For example, Smalltalk supports object-oriented and Haskell supports functional. Most languages support multiple paradigms. For example, a program written in C++, Object Pascal, or PHP can be purely procedural, purely object-oriented, or can contain aspects of both paradigms, or others.
When using a language that supports multiple paradigms, the
developer chooses which paradigm elements to use. But, this choice may
not involve considering paradigms per se. The developer often uses the
features of a language as the language provides them and to the extent
that the developer knows them. Categorizing the resulting code by paradigm is often an academic activity done in retrospect.
Languages categorized as imperative paradigm have two main
features: they state the order in which operations occur, with
constructs that explicitly control that order, and they allow side
effects, in which state can be modified at one point in time, within one
unit of code, and then later read at a different point in time inside a
different unit of code. The communication between the units of code is
not explicit.
In contrast, languages in the declarative paradigm do not
state the order in which to execute operations. Instead, they supply a
number of available operations in the system, along with the conditions
under which each is allowed to execute. The implementation of the language's execution model tracks which
operations are free to execute and chooses the order independently. More
at Comparison of multi-paradigm programming languages.
In object-oriented programming, code is organized into objects
that contain state that is owned by and (usually) controlled by the
code of the object. Most object-oriented languages are also imperative
languages.
In object-oriented programming, programs are treated as a set of interacting objects. In functional programming,
programs are treated as a sequence of stateless function evaluations.
When programming computers or systems with many processors, in process-oriented programming, programs are treated as sets of concurrent processes that act on a logical shared data structures.
Many programming paradigms are as well known for the techniques they forbid as for those they support. For instance, pure functional programming disallows side-effects, while structured programming disallows the goto
construct. Partly for this reason, new paradigms are often regarded as
doctrinaire or overly rigid by those accustomed to older ones. Yet, avoiding certain techniques can make it easier to understand program behavior, and to prove theorems about program correctness.
Programming paradigms can also be compared with programming models, which allows invoking an execution model by using only an API. Programming models can also be classified into paradigms based on features of the execution model.
For parallel computing,
using a programming model instead of a language is common. The reason
is that details of the parallel hardware leak into the abstractions used
to program the hardware. This causes the programmer to have to map
patterns in the algorithm onto patterns in the execution model (which
have been inserted due to leakage of hardware into the abstraction). As
a consequence, no one parallel programming language maps well to all
computation problems. Thus, it is more convenient to use a base
sequential language and insert API calls to parallel execution models
via a programming model. Such parallel programming models can be
classified according to abstractions that reflect the hardware, such as shared memory, distributed memory with message passing, notions of place
visible in the code, and so forth. These can be considered flavors of
programming paradigm that apply to only parallel languages and
programming models.
Criticism
Some programming language researchers criticise the notion of
paradigms as a classification of programming languages, e.g. Harper, and Krishnamurthi. They argue that many programming languages cannot be strictly
classified into one paradigm, but rather include features from several
paradigms. See Comparison of multi-paradigm programming languages.
History
Different approaches to programming have developed over time.
Classification of each approach was either described at the time the
approach was first developed, but often not until some time later,
retrospectively. An early approach consciously identified as such is structured programming, advocated since the mid 1960s. The concept of a programming paradigm as such dates at least to 1978, in the Turing Award lecture of Robert W. Floyd, entitled The Paradigms of Programming, which cites the notion of paradigm as used by Thomas Kuhn in his The Structure of Scientific Revolutions (1962). Early programming languages did not have clearly defined programming
paradigms and sometimes programs made extensive use of goto statements,
liberal use of which led to spaghetti code
which is difficult to understand and maintain. This led to the
development of structured programming paradigms that disallowed the use
of goto statements, only allowing the use of more structured programming
constructs.
Languages and paradigms
Machine code
Machine code is the lowest-level of computer programming as it is machine instructions
that define behavior at the lowest level of abstract possible for a
computer. As it is the most prescriptive way to code it is classified as
imperative.
In the 1960s, assembly languages were developed to support
library COPY and quite sophisticated conditional macro generation and
preprocessing abilities, CALL to subroutine,
external variables and common sections (globals), enabling significant
code re-use and isolation from hardware specifics via the use of logical
operators such as READ/WRITE/GET/PUT. Assembly was, and still is, used
for time-critical systems and often in embedded systems as it gives the most control of what the machine does.
COmmon Business Oriented Language (COBOL) – uses terms like file, move and copy.
FORmula TRANslation (FORTRAN) – using mathematical language terminology, it was developed mainly for scientific and engineering problems.
ALGOrithmic Language (ALGOL) – focused on being an appropriate language to define algorithms, while using mathematical language terminology, targeting scientific and engineering problems, just like FORTRAN.
Programming Language One (PL/I) – a hybrid commercial-scientific general purpose language supporting pointers.
Beginners All purpose Symbolic Instruction Code (BASIC) – it was developed to enable more people to write programs.
C – a general-purpose programming language, initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs.
These languages are classified as procedural paradigm. They directly
control the step by step process that a computer program follows. The efficacy and efficiency of such a program is therefore highly dependent on the programmer's skill.
In attempt to improve on procedural languages, object-oriented programming (OOP) languages were created, such as Simula, Smalltalk, C++, Eiffel, Python, PHP, Java, and C#. In these languages, data and methods to manipulate the data are in the same code unit called an object. This encapsulation ensures that the only way that an object can access data is via methods
of the object that contains the data. Thus, an object's inner workings
may be changed without affecting code that uses the object.
There is controversy raised by Alexander Stepanov, Richard Stallman and other programmers, concerning the efficacy of the OOP paradigm
versus the procedural paradigm. The need for every object to have
associative methods leads some skeptics to associate OOP with software bloat; an attempt to resolve this dilemma came through polymorphism.
Although most OOP languages are third-generation, it is possible to create an object-oriented assembler language. High Level Assembly
(HLA) is an example of this that fully supports advanced data types and
object-oriented assembly language programming – despite its early
origins. Thus, differing programming paradigms can be seen rather like motivational memes of their advocates, rather than necessarily representing progress from one level to the next. Precise comparisons of competing paradigms' efficacy are frequently
made more difficult because of new and differing terminology applied to
similar entities and processes together with numerous implementation
distinctions across languages.
Declarative languages
A declarative programming
program describes what the problem is, not how to solve it. The program
is structured as a set of properties to find in the expected result,
not as a procedure to follow. Given a database or a set of rules, the
computer tries to find a solution matching all the desired properties.
An archetype of a declarative language is the fourth generation languageSQL, and the family of functional languages and logic programming.
Functional programming is a subset of declarative programming. Programs written using this paradigm use functions, blocks of code intended to behave like mathematical functions. Functional languages discourage changes in the value of variables through assignment, making a great deal of use of recursion instead.
The logic programming paradigm views computation as automated reasoning over a body of knowledge. Facts about the problem domain are expressed as logic formulas, and programs are executed by applying inference rules over them until an answer to the problem is found, or the set of formulas is proved inconsistent.
Other paradigms
Symbolic programming is a paradigm that describes programs able to manipulate formulas and program components as data. Programs can thus effectively modify themselves, and appear to "learn", making them suited for applications such as artificial intelligence, expert systems, natural-language processing and computer games. Languages that support this paradigm include Lisp and Prolog.
Literate programming, as a form of imperative programming, structures programs as a human-centered web, as in a hypertext
essay: documentation is integral to the program, and the program is
structured following the logic of prose exposition, rather than compiler
convenience.
Symbolic programming techniques such as reflective programming
(reflection), which allow a program to refer to itself, might also be
considered as a programming paradigm. However, this is compatible with
the major paradigms and thus is not a real paradigm in its own right.
Computer programming or coding is the composition of sequences of instructions, called programs, that computers can follow to perform tasks.It involves designing and implementing algorithms, step-by-step specifications of procedures, by writing code in one or more programming languages. Programmers typically use high-level programming languages that are more easily intelligible to humans than machine code, which is directly executed by the central processing unit. Proficient programming usually requires expertise in several different subjects, including knowledge of the application domain, details of programming languages and generic code libraries, specialized algorithms, and formal logic.
Auxiliary tasks accompanying and related to programming include analyzing requirements, testing, debugging (investigating and fixing problems), implementation of build systems, and management of derived artifacts, such as programs' machine code. While these are sometimes considered programming, often the term software development is used for this larger overall process – with the terms programming, implementation, and coding reserved for the writing and editing of code per se. Sometimes software development is known as software engineering, especially when it employs formal methods or follows an engineering design process.
Programmable devices have existed for centuries. As early as the 9th century, a programmable music sequencer was invented by the Persian Banu Musa brothers, who described an automated mechanical flute player in the Book of Ingenious Devices. In 1206, the Arab engineer Al-Jazari invented a programmable drum machine where a musical mechanical automaton could be made to play different rhythms and drum patterns, via pegs and cams. In 1801, the Jacquard loom could produce entirely different weaves by changing the "program" – a series of pasteboard cards with holes punched in them.
Code-breaking algorithms have also existed for centuries. In the 9th century, the Arab mathematicianAl-Kindi described a cryptographic algorithm for deciphering encrypted code, in A Manuscript on Deciphering Cryptographic Messages. He gave the first description of cryptanalysis by frequency analysis, the earliest code-breaking algorithm.
The first computer program is generally dated to 1843 when mathematician Ada Lovelace published an algorithm to calculate a sequence of Bernoulli numbers, intended to be carried out by Charles Babbage's Analytical Engine. The algorithm, which was conveyed through notes on a translation of
Luigi Federico Menabrea's paper on the analytical engine was mainly
conceived by Lovelace as can be discerned through her correspondence
with Babbage. However, Charles Babbage himself had written a program for
the AE in 1837. Lovelace was also the first to see a broader application for the analytical engine beyond mathematical calculations.
Data and instructions were once stored on external punched cards, which were kept in order and arranged in program decks.
In the 1880s, Herman Hollerith invented the concept of storing data in machine-readable form. Later a control panel (plug board) added to his 1906 Type I Tabulator allowed it to be programmed for different jobs, and by the late 1940s, unit record equipment such as the IBM 602 and IBM 604, were programmed by control panels in a similar way, as were the first electronic computers. However, with the concept of the stored-program computer introduced in 1949, both programs and data were stored and manipulated in the same way in computer memory. Hands-on programming courses that integrate hardware and software have
been shown to improve retention and engagement among first-year
engineering students.
Machine language
Machine code was the language of early programs, written in the instruction set of the particular machine, often in binary notation. Soon, assembly languages
were developed, allowing programmers to write instructions in a textual
format (e.g., ADD X, TOTAL), using abbreviations for operation codes
and meaningful names for memory addresses. However, because an assembly
language is little more than a different notation for a machine
language, two machines with different instruction sets also have different assembly languages.
Wired control panel for an IBM 402 Accounting Machine. Wires connect pulse streams from the card reader to counters and other internal logic and ultimately to the printer.
High-level languages made the process of developing a program simpler and more understandable, and less bound to the underlying hardware.
The first compiler related tool, the A-0 System, was developed in 1952 by Grace Hopper, who also coined the term 'compiler'. FORTRAN, the first widely used high-level language to have a functional implementation, came out in 1957, and many other languages were soon developed—in particular, COBOL aimed at commercial data processing, and Lisp for computer research.
These compiled languages allow the programmer to write programs in terms that are syntactically richer, and more capable of abstracting the code, making it easy to target varying machine instruction sets via compilation declarations and heuristics. Compilers harnessed the power of computers to make programming easier by allowing programmers to specify calculations by entering a formula using infix notation.
Programs were mostly entered using punched cards or paper tape. By the late 1960s, data storage devices and computer terminals became inexpensive enough that programs could be created by typing directly into the computers. Text editors were also developed that allowed changes and corrections to be made much more easily than with punched cards.
Whatever the approach to development may be, the final program must
satisfy some fundamental properties. The following properties are among
the most important:
Reliability:
how often the results of a program are correct. This depends on
conceptual correctness of algorithms and minimization of programming
mistakes, such as mistakes in resource management (e.g., buffer overflows and race conditions) and logic errors (such as division by zero or off-by-one errors).
Robustness:
how well a program anticipates problems due to errors (not bugs). This
includes situations such as incorrect, inappropriate or corrupt data,
unavailability of needed resources such as memory, operating system
services, and network connections, user error, and unexpected power
outages.
Usability: the ergonomics
of a program: the ease with which a person can use the program for its
intended purpose or in some cases even unanticipated purposes. Such
issues can make or break its success even regardless of other issues.
This involves a wide range of textual, graphical, and sometimes hardware
elements that improve the clarity, intuitiveness, cohesiveness, and
completeness of a program's user interface.
Portability: the range of computer hardware and operating system platforms on which the source code of a program can be compiled/interpreted
and run. This depends on differences in the programming facilities
provided by the different platforms, including hardware and operating
system resources, expected behavior of the hardware and operating
system, and availability of platform-specific compilers (and sometimes
libraries) for the language of the source code.
Maintainability:
the ease with which a program can be modified by its present or future
developers in order to make improvements or to customize, fix bugs and security holes, or adapt it to new environments. Good practices during initial development make the difference in this regard. This
quality may not be directly apparent to the end user but it can
significantly affect the fate of a program over the long term.
Efficiency/performance:
Measure of system resources a program consumes (processor time, memory
space, slow devices such as disks, network bandwidth and to some extent
even user interaction): the less, the better. This also includes careful
management of resources, for example cleaning up temporary files and eliminating memory leaks.
This is often discussed under the shadow of a chosen programming
language. Although the language certainly affects performance, even
slower languages, such as Python,
can execute programs instantly from a human perspective. Speed,
resource usage, and performance are important for programs that bottleneck the system, but efficient use of programmer time is also important and is related to cost: more hardware may be cheaper.
In computer programming, readability refers to the ease with which a human reader can comprehend the purpose, control flow, and operation of source code. It affects the aspects of quality above, including portability, usability and most importantly maintainability.
Source code in integrated development environment
Readability is important because programmers spend the majority of
their time reading, trying to understand, reusing, and modifying
existing source code, rather than writing new source code. Unreadable
code often leads to bugs, inefficiencies, and duplicated code.
A study found that a few simple readability transformations made code
shorter and drastically reduced the time to understand it.
Following a consistent programming style
often helps readability. However, readability is more than just
programming style. Many factors, having little or nothing to do with the
ability of the computer to efficiently compile and execute the code,
contribute to readability. Some of these factors include:
Naming conventions for objects (such as variables, classes, functions, procedures, etc.)
The presentation aspects of this (such as indents, line breaks, color highlighting, and so on) are often handled by the source code editor, but the content aspects reflect the programmer's talent and skills.
The academic field and the engineering practice of computer
programming are concerned with discovering and implementing the most
efficient algorithms for a given class of problems. For this purpose,
algorithms are classified into orders using Big O notation,
which expresses resource use—such as execution time or memory
consumption—in terms of the size of an input. Expert programmers are
familiar with a variety of well-established algorithms and their
respective complexities and use this knowledge to choose algorithms that
are best suited to the circumstances.
Methodologies
The first step in most formal software development processes is requirements analysis,
followed by testing to determine value modeling, implementation, and
failure elimination (debugging). There exist a lot of different
approaches for each of those tasks. One approach popular for
requirements analysis is Use Case analysis. Many programmers use forms of Agile software development
where the various stages of formal software development are more
integrated together into short cycles that take a few weeks rather than
years. There are many approaches to the Software development process.
Popular modeling techniques include Object-Oriented Analysis and Design (OOAD) and Model-Driven Architecture (MDA). The Unified Modeling Language (UML) is a notation used for both the OOAD and MDA.
A similar technique used for database design is Entity-Relationship Modeling (ER Modeling).
It is very difficult to determine what are the most popular modern
programming languages. Methods of measuring programming language
popularity include: counting the number of job advertisements that
mention the language, the number of books sold and courses teaching the language (this
overestimates the importance of newer languages), and estimates of the
number of existing lines of code written in the language (this
underestimates the number of users of business languages such as COBOL).
Some languages are popular for writing particular kinds of
applications, while other languages are used to write many different
kinds of applications. For example, COBOL is still prevalent in corporate data centers often on large mainframe computers, Fortran in engineering applications, scripting languages in Web development, and C in embedded software.
Many applications use a mix of several languages in their construction
and use. New languages are generally designed around the syntax of a
prior language with new functionality added, (for example C++ adds object-orientation to C, and Java adds memory management and bytecode to C++, but as a result, loses efficiency and the ability for low-level manipulation).
The
first known actual bug causing a problem in a computer was a moth,
trapped inside a Harvard mainframe, recorded in a log book entry dated
September 9, 1947. "Bug" was already a common term for a software defect when this insect was found.
Debugging is a very important task in the software development
process since having defects in a program can have significant
consequences for its users. Some languages are more prone to some kinds
of faults because their specification does not require compilers to
perform as much checking as other languages. Use of a static code analysis
tool can help detect some possible problems. Normally the first step in
debugging is to attempt to reproduce the problem. This can be a
non-trivial task, for example as with parallel processes or some unusual
software bugs. Also, specific user environment and usage history can
make it difficult to reproduce the problem.
After the bug is reproduced, the input of the program may need to
be simplified to make it easier to debug. For example, when a bug in a
compiler can make it crash when parsing
some large source file, a simplification of the test case that results
in only few lines from the original source file can be sufficient to
reproduce the same crash. Trial-and-error/divide-and-conquer is needed:
the programmer will try to remove some parts of the original test case
and check if the problem still exists. When debugging the problem in a
GUI, the programmer can try to skip some user interaction from the
original problem description and check if the remaining actions are
sufficient for bugs to appear. Scripting and breakpointing are also part of this process.
Debugging is often done with IDEs. Standalone debuggers like GDB are also used, and these often provide less of a visual environment, usually using a command line. Some text editors such as Emacs
allow GDB to be invoked through them, to provide a visual environment.
One study found that teaching structured languages such as Pascal
improved novice programmers’ debugging accuracy and overall
comprehension.
Different programming languages support different styles of programming (called programming paradigms).
The choice of language used is subject to many considerations, such as
company policy, suitability to task, availability of third-party
packages, or individual preference. Ideally, the programming language
best suited for the task at hand will be selected. Trade-offs from this
ideal involve finding enough programmers who know the language to build a
team, the availability of compilers for that language, and the
efficiency with which programs written in a given language execute.
Languages form an approximate spectrum from "low-level" to "high-level";
"low-level" languages are typically more machine-oriented and faster to
execute, whereas "high-level" languages are more abstract and easier to
use but execute less quickly. It is usually easier to code in
"high-level" languages than in "low-level" ones.
Programming languages are essential for software development. They are
the building blocks for all software, from the simplest applications to
the most sophisticated ones.
Allen Downey, in his book How To Think Like A Computer Scientist, writes:
The details look different in different languages, but a few basic instructions appear in just about every language:
Input: Gather data from the keyboard, a file, or some other device.
Output: Display data on the screen or send data to a file or other device.
Arithmetic: Perform basic arithmetical operations like addition and multiplication.
Conditional Execution: Check for certain conditions and execute the appropriate sequence of statements.
Repetition: Perform some action repeatedly, usually with some variation.
Many computer languages provide a mechanism to call functions provided by shared libraries. Provided the functions in a library follow the appropriate run-time conventions (e.g., method of passing arguments),
then these functions may be written in any other language. Annual
rankings by IEEE Spectrum analyze programming language popularity using
metrics such as job postings, search trends, and developer activity.
Learning to program has a long history related to professional
standards and practices, academic initiatives and curriculum, and
commercial books and materials for students, self-taught learners,
hobbyists, and others who desire to create or customize software for
personal use. Since the 1960s, learning to program has taken on the
characteristics of a popular movement, with the rise of academic
disciplines, inspirational leaders, collective identities, and
strategies to grow the movement and make institutionalize change. Through these social ideals and educational agendas, learning to code
has become important not just for scientists and engineers, but for
millions of citizens who have come to believe that creating software is
beneficial to society and its members. Computer science education
participation has expanded significantly in recent years, with millions
of students gaining introductory programming experience through schools
and online platforms.
Context
In 1957, there were approximately 15,000 computer programmers
employed in the U.S., a figure that accounts for 80% of the world's
active developers. In 2014, there were approximately 18.5 million
professional programmers in the world, of which 11 million can be
considered professional and 7.5 million student or hobbyists. Before the rise of the commercial Internet in the mid-1990s, most
programmers learned about software construction through books,
magazines, user groups, and informal instruction methods, with academic
coursework and corporate training playing important roles for
professional workers.
The first book containing specific instructions about how to program a computer may have been Maurice Wilkes, David Wheeler, and Stanley Gill'sPreparation of Programs for an Electronic Digital Computer
(1951). The book offered a selection of common subroutines for handling
basic operations on the EDSAC, one of the world's first stored-program
computers.
When high-level languages arrived, they were introduced by
numerous books and materials that explained language keywords, managing
program flow, working with data, and other concepts. These languages
included FLOW-MATIC, COBOL, FORTRAN, ALGOL, Pascal, BASIC, and C. An example of an early programming primer from these years is Marshal H. Wrubel'sA Primer of Programming for Digital Computers
(1959), which included step-by-step instructions for filling out coding
sheets, creating punched cards, and using the keywords in IBM's early
FORTRAN system. Daniel McCracken'sA Guide to FORTRAN Programming (1961) presented FORTRAN to a larger audience, including students and office workers.
In 1961, Alan Perlis suggested that all university freshmen at Carnegie Technical Institute take a course in computer programming. His advice was published in the popular technical journal Computers and Automation, which became a regular source of information for professional programmers.
Programmers soon had a range of learning texts at their disposal. Programmer's references
listed keywords and functions related to a language, often in
alphabetical order, as well as technical information about compilers and
related systems. An early example was IBM's Programmers' Reference Manual: the FORTRAN Automatic Coding System for the IBM 704 EDPM (1956).
Over time, the genre of programmer's guides emerged, which
presented the features of a language in tutorial or step by step
format. Many early primers started with a program known as "Hello, World",
which presented the shortest program a developer could create in a
given system. Programmer's guides then went on to discuss core topics
like declaring variables, data types, formulas, flow control,
user-defined functions, manipulating data, and other topics.
Early and influential programmer's guides included John G. Kemeny and Thomas E. Kurtz'sBASIC Programming (1967), Kathleen Jensen and Niklaus Wirth'sThe Pascal User Manual and Report (1971), and Brian W. Kernighan and Dennis Ritchie'sThe C Programming Language (1978). Similar books for popular audiences (but with a much lighter tone) included Bob Albrecht'sMy Computer Loves Me When I Speak BASIC (1972), Al Kelley and Ira Pohl's A Book on C (1984), and Dan Gookin'sC for Dummies (1994).
Beyond language-specific primers, there were numerous books and
academic journals that introduced professional programming practices.
Many were designed for university courses in computer science, software
engineering, or related disciplines. Donald Knuth'sThe Art of Computer Programming (1968 and later), presented hundreds of computational algorithms and their analysis. The Elements of Programming Style (1974), by Brian W. Kernighan and P. J. Plauger, concerned itself with programming style, the idea that programs should be written not only to satisfy the compiler but human readers. Jon Bentley'sProgramming Pearls
(1986) offered practical advice about the art and craft of programming
in professional and academic contexts. Texts specifically designed for
students included Doug Cooper and Michael Clancy's Oh Pascal! (1982), Alfred Aho'sData Structures and Algorithms (1983), and Daniel Watt's Learning with Logo (1983).
Between 2000 and 2010, computer book and magazine publishers declined
significantly as providers of programming instruction, as programmers
moved to Internet resources to expand their access to information. This
shift brought forward new digital products and mechanisms to learn
programming skills. During the transition, digital books from publishers
transferred information that had traditionally been delivered in print
to new and expanding audiences.
Important Internet resources for learning to code included blogs, books, wikis, videos, online databases, journals, subscription sites, conference papers. and custom websites focused on coding skills. In recent years, platforms like LeetCode, HackerRank, and freeCodeCamp
have become popular for learning programming, practicing coding
challenges, and preparing for technical interviews. New commercial
resources included YouTube videos, Lynda.com tutorials (later LinkedIn Learning), Khan Academy, Codecademy, GitHub, W3Schools, Codewars, and numerous coding bootcamps.
Commercial and non-profit organizations published learning
websites for developers, created blogs, and established news feeds and
social media resources about programming. Corporations like Apple, Microsoft, Oracle, Google, and Amazon built corporate websites providing support for programmers, including resources like the Microsoft Developer Network (MSDN). Contemporary movements like Hour of Code (Code.org)
show how learning to program has become associated with digital
learning strategies, education agendas, and corporate philanthropy.
Execution of a program requires an implementation. There are two main approaches for implementing a programming language – compilation, where programs are compiled ahead-of-time to machine code, and interpretation, where programs are directly executed. In addition to these two extremes, some implementations use hybrid approaches such as just-in-time compilation and bytecode interpreters.
Programming languages have some similarity to natural languages
in that they can allow communication of ideas between people. That is,
programs are generally human-readable and can express complex ideas.
However, the kinds of ideas that programming languages can express are
ultimately limited to the domain of computation.
The term computer language is sometimes used interchangeably with programming language but some contend they are different concepts. Some contend that programming languages are a subset of computer languages. Some use computer language to classify a language used in computing that is not considered a programming language. Some regard a programming language as a theoretical construct for programming an abstract machine, and a computer language as the subset thereof that runs on a physical computer, which has finite hardware resources.
John C. Reynolds emphasizes that a formal specification
language is as much a programming language as it is a language intended
for execution. He argues that textual and even graphical input formats
that affect the behavior of a computer are programming languages,
despite the fact they are commonly not Turing-complete, and remarks that
ignorance of programming language concepts is the reason for many flaws
in input formats.
The first programmable computers were invented during the 1940s, and with them, the first programming languages. The earliest computers were programmed in first-generation programming languages (1GLs), machine language (simple instructions that could be directly executed by the processor). This code was very difficult to debug and was not portable between different computer systems. In order to improve the ease of programming, assembly languages (or second-generation programming languages—2GLs)
were invented, diverging from the machine language to make programs
easier to understand for humans, although they did not increase
portability.
Initially, hardware resources were scarce and expensive, while human resources
were cheaper. Therefore, cumbersome languages that were time-consuming
to use, but were closer to the hardware for higher efficiency were
favored. The introduction of high-level programming languages (third-generation programming languages—3GLs)—revolutionized programming. These languages abstracted away the details of the hardware, instead being designed to express algorithms
that could be understood more easily by humans. For example, arithmetic
expressions could now be written in symbolic notation and later
translated into machine code that the hardware could execute. In 1957, Fortran (FORmula TRANslation) was invented. Often considered the first compiled high-level programming language, Fortran has remained in use into the twenty-first century.
Around 1960, the first mainframes—general
purpose computers—were developed, although they could only be operated
by professionals and the cost was extreme. The data and instructions
were input by punch cards,
meaning that no input could be added while the program was running. The
languages developed at this time therefore are designed for minimal
interaction. After the invention of the microprocessor, computers in the 1970s became dramatically cheaper. New computers also allowed more user interaction, which was supported by newer programming languages.
After ALGOL (ALGOrithmic Language) was released in 1958 and 1960, it became the standard in computing literature for describing algorithms. Although its commercial success was limited, most popular imperative languages—including C, Pascal, Ada, C++, Java, and C#—are directly or indirectly descended from ALGOL 60. Among its innovations adopted by later programming languages included greater portability and the first use of context-free, BNF grammar. Simula, the first language to support object-oriented programming (including subtypes, dynamic dispatch, and inheritance), also descends from ALGOL and achieved commercial success. C, another ALGOL descendant, has sustained popularity into the
twenty-first century. C allows access to lower-level machine operations
than other contemporary languages. Its power and efficiency, generated
in part with flexible pointer operations, comes at the cost of making it more difficult to write correct code.
Prolog, designed in 1972, was the first logic programming language, communicating with a computer using formal logic notation. With logic programming, the programmer specifies a desired result and allows the interpreter to decide how to achieve it.
1980s to 2000s
A small selection of programming language textbooks
During the 1980s, the invention of the personal computer transformed the roles for which programming languages were used. New languages introduced in the 1980s included C++, a superset of C that can compile C programs but also supports classes and inheritance. Ada and other new languages introduced support for concurrency. The Japanese government invested heavily into the so-called fifth-generation languages
that added support for concurrency to logic programming constructs, but
these languages were outperformed by other concurrency-supporting
languages.
Due to the rapid growth of the Internet and the World Wide Web in the 1990s, new programming languages were introduced to support web pages and networking. Java,
based on C++ and designed for increased portability across systems and
security, enjoyed large-scale success because these features are
essential for many Internet applications.Another development was that of dynamically typedscripting languages—Python, JavaScript, PHP, and Ruby—designed to quickly produce small programs that coordinate existing applications. Due to their integration with HTML, they have also been used for building web pages hosted on servers.
2000s to present
During the 2000s, there was a slowdown in the development of new programming languages that achieved widespread popularity.[42] One innovation was service-oriented programming, designed to exploit distributed computing
systems which components are connected by a network. Services are
similar to objects in object-oriented programming, but run on a separate
process. C# and F# cross-pollinated ideas between imperative and functional programming. After 2010, several new languages—Rust, Go, Swift, Zig, and Carbon —competed for the performance-critical software for which C had historically been used. Most of the new programming languages use static typing while a few numbers of new languages use dynamic typing like Julia.
Some of the new programming languages are classified as visual programming languages like Scratch and LabVIEW. Also, some of these languages mix between textual and visual programming usage like Ballerina. Also, this trend lead to developing projects that help in developing new visual languages like Blockly by Google. Many game engines like Unreal and Unity support visual scripting.
Definition
A language can be defined in terms of syntax (form) and semantics (meaning), and often is defined via a formal language specification.
A programming language's surface form is known as its syntax.
Most programming languages are purely textual; they use sequences of
text including words, numbers, and punctuation, much like written
natural languages. In contrast, some programming languages are graphical, using visual relationships between symbols to specify a program.
The syntax of a language describes the possible combinations of
symbols that form a syntactically correct program. The meaning given to a
combination of symbols is handled by semantics (either formal or hard-coded in a reference implementation). Since most languages are textual, this article discusses textual syntax.
expression ::= atom | list
atom ::= number | symbol
number ::= [+-]?['0'-'9']+
symbol ::= ['A'-'Z''a'-'z'].*
list ::= '(' expression* ')'
This grammar specifies the following:
an expression is either an atom or a list;
an atom is either a number or a symbol;
a number is an unbroken sequence of one or more decimal digits, optionally preceded by a plus or minus sign;
a symbol is a letter followed by zero or more of any alphabetical characters (excluding whitespace); and
a list is a matched pair of parentheses, with zero or more expressions inside it.
The following are examples of well-formed token sequences in this grammar: 12345, () and (a b c232 (1)).
Not all syntactically correct programs are semantically correct.
Many syntactically correct programs are nonetheless ill-formed, per the
language's rules, and may (depending on the language specification and
the soundness of the implementation) result in an error on translation
or execution. In some cases, such programs may exhibit undefined behavior.
Even when a program is well-defined within a language, it may still
have a meaning that is not intended by the person who wrote it.
Using natural language as an example, it may not be possible to assign a meaning to a grammatically correct sentence or the sentence may be false:
"John is a married bachelor," is grammatically well-formed but expresses a meaning that cannot be true.
The following C language fragment is syntactically correct, but performs operations that are not semantically defined (the operation *p >> 4 has no meaning for a value having a complex type and p->im is not defined because the value of p is the null pointer):
complex*p=NULL;complexabs_p=sqrt(*p>>4+p->im);
If the type declaration on the first line were omitted, the program would trigger an error on the undefined variable p
during compilation. However, the program would still be syntactically
correct since type declarations provide only semantic information.
The grammar needed to specify a programming language can be classified by its position in the Chomsky hierarchy. The syntax of most programming languages can be specified using a Type-2 grammar, i.e., they are context-free grammars. Some languages, including Perl and Lisp, contain constructs that allow
execution during the parsing phase. Languages that have constructs that
allow the programmer to alter the behavior of the parser make syntax
analysis an undecidable problem, and generally blur the distinction between parsing and execution. In contrast to Lisp's macro system and Perl's BEGIN blocks, which may contain general computations, C macros are merely string replacements and do not require code execution.
Semantics refers to the meaning of content that conforms to a language's syntax.
Static semantics
Static semantics defines restrictions on the structure of valid texts
that are hard or impossible to express in standard syntactic
formalisms. For compiled languages, static semantics essentially include those
semantic rules that can be checked at compile time. Examples include
checking that every identifier is declared before it is used (in languages that require such declarations) or that the labels on the arms of a case statement are distinct. Many important restrictions of this type, like checking that
identifiers are used in the appropriate context (e.g. not adding an
integer to a function name), or that subroutine calls have the appropriate number and type of arguments, can be enforced by defining them as rules in a logic called a type system. Other forms of static analyses like data flow analysis may also be part of static semantics. Programming languages such as Java and C# have definite assignment analysis, a form of data flow analysis, as part of their respective static semantics.
Once data has been specified, the machine must be instructed to
perform operations on the data. For example, the semantics may define
the strategy by which expressions are evaluated to values, or the manner in which control structures conditionally execute statements. The dynamic semantics (also known as execution semantics)
of a language defines how and when the various constructs of a language
should produce a program behavior. There are many ways of defining
execution semantics. Natural language is often used to specify the
execution semantics of languages commonly used in practice. A
significant amount of academic research goes into formal semantics of programming languages,
which allows execution semantics to be specified in a formal manner.
Results from this field of research have seen limited application to
programming language design and implementation outside academia.
Features
A language provides features for a programmer to develop software. Some notable features are described below.
A data type is a set of allowable values and operations that can be performed on these values. Each programming language's type system defines which data types exist, the type of an expression, and how type equivalence and type compatibility function in the language.
According to type theory, a language is fully typed if the specification of every operation defines types of data to which the operation is applicable. In contrast, an untyped language, such as most assembly languages, allows any operation to be performed on any data, generally sequences of bits of various lengths. In practice, while few languages are fully typed, most offer a degree of typing.
Because different types (such as integers and floats) represent values differently, unexpected results will occur if one type is used when another is expected. Type checking will flag this error, usually at compile time (runtime type checking is more costly). With strong typing, type errors can always be detected unless variables are explicitly cast to a different type. Weak typing
occurs when languages allow implicit casting—for example, to enable
operations between variables of different types without the programmer
making an explicit type conversion. The more cases in which this type coercion is allowed, the fewer type errors can be detected.
Early programming languages often supported only built-in, numeric types such as the integer (signed and unsigned) and floating point (to support operations on real numbers that are not integers). Most programming languages support multiple sizes of floats (often called float and double)
and integers depending on the size and precision required by the
programmer. Storing an integer in a type that is too small to represent
it leads to integer overflow. The most common way of representing negative numbers with signed types is twos complement, although ones complement is also used. Other common types include Boolean—which is either true or false—and character—traditionally one byte, sufficient to represent all ASCII characters.
Arrays
are a data type whose elements, in many languages, must consist of a
single type of fixed length. Other languages define arrays as references
to data stored elsewhere and support elements of varying types. Depending on the programming language, sequences of multiple characters, called strings, may be supported as arrays of characters or their own primitive type. Strings may be of fixed or variable length, which enables greater
flexibility at the cost of increased storage space and more complexity. Other data types that may be supported include lists, associative (unordered) arrays accessed via keys, records in which data is mapped to names in an ordered structure, and tuples—similar to records but without names for data fields. Pointers store memory addresses, typically referencing locations on the heap where other data is stored.
The simplest user-defined type is an ordinal type, often called an enumeration, whose values can be mapped onto the set of positive integers. Since the mid-1980s, most programming languages also support abstract data types, in which the representation of the data and operations are hidden from the user, who can only access an interface. The benefits of data abstraction can include increased reliability, reduced complexity, less potential for name collision, and allowing the underlying data structure to be changed without the client needing to alter its code.
Static and dynamic typing
In static typing, all expressions have their types determined before a program executes, typically at compile-time. Most widely used, statically typed programming languages require the
types of variables to be specified explicitly. In some languages, types
are implicit; one form of this is when the compiler can infer types based on context. The downside of implicit typing is the potential for errors to go undetected. Complete type inference has traditionally been associated with functional languages such as Haskell and ML.
With dynamic typing,
the type is not attached to the variable but only the value encoded in
it. A single variable can be reused for a value of a different type.
Although this provides more flexibility to the programmer, it is at the
cost of lower reliability and less ability for the programming language
to check for errors. Some languages allow variables of a union type to which any type of value can be assigned, in an exception to their usual static typing rules.
In computing, multiple instructions can be executed simultaneously.
Many programming languages support instruction-level and
subprogram-level concurrency. By the twenty-first century, additional processing power on computers
was increasingly coming from the use of additional processors, which
requires programmers to design software that makes use of multiple
processors simultaneously to achieve improved performance. Interpreted languages such as Python and Ruby do not support the concurrent use of multiple processors. Other programming languages do support managing data shared between
different threads by controlling the order of execution of key
instructions via the use of semaphores, controlling access to shared data via monitor, or enabling message passing between threads.
Many programming languages include exception handlers, a section of code triggered by runtime errors that can deal with them in two main ways:
Termination: shutting down and handing over control to the operating system. This option is considered the simplest.
Resumption: resuming the program near where the exception occurred.
This can trigger a repeat of the exception, unless the exception handler
is able to modify values to prevent the exception from reoccurring.
Some programming languages support dedicating a block of code to run
regardless of whether an exception occurs before the code is reached;
this is called finalization.
There is a tradeoff between increased ability to handle exceptions and reduced performance. For example, even though array index errors are common C does not check them for performance reasons. Although programmers can write code to catch user-defined exceptions,
this can clutter a program. Standard libraries in some languages, such
as C, use their return values to indicate an exception. Some languages and their compilers have the option of turning on and
off error handling capability, either temporarily or permanently.
One of the most important influences on programming language design has been computer architecture. Imperative languages, the most commonly used type, were designed to perform well on von Neumann architecture, the most common digital computer architecture. In von Neumann architecture, the memory stores both data and instructions, while the CPU
that performs instructions on data is separate, and data must be piped
back and forth to the CPU. The central elements in these languages are
variables, assignment, and iteration, which is more efficient than recursion on these machines.
Many programming languages have been designed from scratch,
altered to meet new needs, and combined with other languages. Many have
eventually fallen into disuse. The birth of programming languages in the 1950s was stimulated by the
desire to make a universal programming language suitable for all
machines and uses, avoiding the need to write code for different
computers. By the early 1960s, the idea of a universal language was rejected due
to the differing requirements of the variety of purposes for which code
was written.
Tradeoffs
Desirable qualities of programming languages include readability, writability, and reliability. These features can reduce the cost of training programmers in a
language, the amount of time needed to write and maintain programs in
the language, the cost of compiling the code, and increase runtime
performance.
Although early programming languages often prioritized
efficiency over readability, the latter has grown in importance since
the 1970s. Having multiple operations to achieve the same result can be
detrimental to readability, as is overloading operators, so that the same operator can have multiple meanings. Another feature important to readability is orthogonality, limiting the number of constructs that a programmer has to learn. A syntax structure that is easily understood and special words that are immediately obvious also supports readability.
Writability is the ease of use for writing code to solve the desired
problem. Along with the same features essential for readability, abstraction—interfaces that enable hiding details from the client—and expressivity—enabling more concise programs—additionally help the programmer write code. The earliest programming languages were tied very closely to the
underlying hardware of the computer, but over time support for
abstraction has increased, allowing programmers to express ideas that
are more remote from simple translation into underlying hardware
instructions. Because programmers are less tied to the complexity of the
computer, their programs can do more computing with less effort from
the programmer. Most programming languages come with a standard library of commonly used functions.
Reliability means that a program performs as specified in a wide range of circumstances. Type checking, exception handling, and restricted aliasing (multiple variable names accessing the same region of memory) all can improve a program's reliability.
Programming language design often involves tradeoffs. For example, features to improve reliability typically come at the cost of performance. Increased expressivity due to a large number of operators makes writing code easier but comes at the cost of readability.
Natural-language programming
has been proposed as a way to eliminate the need for a specialized
language for programming. However, this goal remains distant and its
benefits are open to debate. Edsger W. Dijkstra took the position that the use of a formal language is essential to prevent the introduction of meaningless constructs. Alan Perlis was similarly dismissive of the idea.
The specification of a programming language is an artifact that the language users and the implementors can use to agree upon whether a piece of source code is a valid program in that language, and if so what its behavior shall be.
A programming language specification can take several forms, including the following:
An explicit definition of the syntax, static semantics, and
execution semantics of the language. While syntax is commonly specified
using a formal grammar, semantic definitions may be written in natural language (e.g., as in the C language), or a formal semantics (e.g., as in Standard ML and Scheme specifications).
A description of the behavior of a translator for the language (e.g., the C++ and Fortran
specifications). The syntax and semantics of the language have to be
inferred from this description, which may be written in natural or
formal language.
An implementation of a programming language is the conversion of a program into machine code that can be executed by the hardware. The machine code then can be executed with the help of the operating system. The most common form of interpretation in production code is by a compiler, which translates the source code via an intermediate-level language into machine code, known as an executable. Once the program is compiled, it will run more quickly than with other implementation methods. Some compilers are able to provide further optimization to reduce memory or computation usage when the executable runs, but increasing compilation time.
Another implementation method is to run the program with an interpreter,
which translates each line of software into machine code just before it
executes. Although it can make debugging easier, the downside of
interpretation is that it runs 10 to 100 times slower than a compiled
executable. Hybrid interpretation methods provide some of the benefits of
compilation and some of the benefits of interpretation via partial
compilation. One form this takes is just-in-time compilation,
in which the software is compiled ahead of time into an intermediate
language, and then into machine code immediately before execution.
Proprietary languages
Although most of the most commonly used programming languages have
fully open specifications and implementations, many programming
languages exist only as proprietary programming languages with the
implementation available only from a single vendor, which may claim that
such a proprietary language is their intellectual property. Proprietary
programming languages are commonly domain-specific languages or internal scripting languages
for a single product; some proprietary languages are used only
internally within a vendor, while others are available to external
users.
Some programming languages exist on the border between proprietary and open; for example, Oracle Corporation asserts proprietary rights to some aspects of the Java programming language, and Microsoft's C# programming language, which has open implementations of most parts of the system, also has Common Language Runtime (CLR) as a closed environment.
Many proprietary languages are widely used, in spite of their proprietary nature; examples include MATLAB, VBScript, and Wolfram Language. Some languages may make the transition from closed to open; for example, Erlang was originally Ericsson's internal programming language.
Thousands of different programming languages have been created, mainly in the computing field. Individual software projects commonly use five programming languages or more.
Programming languages differ from most other forms of human
expression in that they require a greater degree of precision and
completeness. When using a natural language to communicate with other
people, human authors and speakers can be ambiguous and make small
errors, and still expect their intent to be understood. However,
figuratively speaking, computers "do exactly what they are told to do",
and cannot "understand" what code the programmer intended to write. The
combination of the language definition, a program, and the program's
inputs must fully specify the external behavior that occurs when the
program is executed, within the domain of control of that program. In
contrast, ideas about an algorithm can be communicated to humans without
the precision needed for execution by using pseudocode, which interleaves natural language with code written in a programming language.
A programming language provides a structured mechanism for
defining pieces of data, and the operations or transformations that may
be carried out automatically on that data. A programmer uses the abstractions
present in the language to represent the concepts involved in a
computation. These concepts are represented as a collection of the
simplest elements available (called primitives). Programming
is the process by which programmers combine these primitives to compose
new programs, or adapt existing ones to new uses or a changing
environment.
Determining which is the most widely used programming language is
difficult since the definition of usage varies by context. One language
may occupy the greater number of programmer hours, a different one has
more lines of code, and a third may consume the most CPU time. Some
languages are very popular for particular kinds of applications. For
example, COBOL is still strong in the corporate data center, often on large mainframesFortran in scientific and engineering applications; Ada in aerospace, transportation, military, real-time, and embedded applications; and C
in embedded applications and operating systems. Other languages are
regularly used to write many different kinds of applications.
Various methods of measuring language popularity, each subject to a different bias over what is measured, have been proposed:
counting the number of job advertisements that mention the language
the number of books sold that teach or describe the language
estimates of the number of existing lines of code written in the
language – which may underestimate languages not often found in public
searches
counts of language references (i.e., to the name of the language) found using a web search engine.
Combining and averaging information from various internet sites,
stackify.com reported the ten most popular programming languages (in
descending order by overall popularity): Java, C, C++, Python, C#, JavaScript, VB .NET, R, PHP, and MATLAB.
As of June 2024, the top five programming languages as measured by TIOBE index are Python, C++, C, Java and C#. TIOBE provides a list of the top 100 programming languages according to their index and updates this list every month.
According to IEEE Spectrum staff, today's most popular
programming languages may remain dominant because of how AI works. As a
result, new languages will have a harder time gaining popularity since
coders will not write many programs in them.
Dialects, flavors and implementations
A dialect of a programming language or a data exchange language
is a (relatively small) variation or extension of the language that
does not change its intrinsic nature. With languages such as Scheme and Forth,
standards may be considered insufficient, inadequate, or illegitimate
by implementors, so often they will deviate from the standard, making a
new dialect. In other cases, a dialect is created for use in a domain-specific language, often a subset. In the Lisp world, most languages that use basic S-expression syntax and Lisp-like semantics are considered Lisp dialects, although they vary wildly as do, say, Racket and Clojure.
As it is common for one language to have several dialects, it can
become quite difficult for an inexperienced programmer to find the right
documentation. The BASIC language has many dialects.
Programming languages can be described per the following high-level yet sometimes overlapping classifications:
Imperative
An imperative programming
language supports implementing logic encoded as a sequence of ordered
operations. Most popularly used languages are classified as imperative.
Functional
A functional programming
language supports successively applying functions to the given
parameters. Although appreciated by many researchers for their
simplicity and elegance, problems with efficiency have prevented them
from being widely adopted.
Logic
A logic programming
language is designed so that the software, rather than the programmer,
decides what order in which the instructions are executed.