Encyclopedia
A
programming language is an artificial language that can be used to control the behavior of a machine, particularly a
computer. Programming languages, like human languages, have syntactic and semantic rules to define meaning.
Programming languages are used to facilitate communication about the task of organizing and manipulating information, and to express
algorithms precisely. Some authors restrict the term "programming language" to those languages that can express
all possible algorithms; sometimes the term "computer language" is used for more limited artificial languages.
Thousands of different programming languages have been created and new ones are created every year. Few languages ever become sufficiently popular that they are used by more than a few people, but professional programmers may use dozens of different languages during their careers.
Definitions
Authors disagree on the precise definition of
programming language. Traits often considered important include:
- Function: A programming language is a language used to write computer programs, which instruct a computer to perform some kind of computation and/or organize the flow of control between mechanical devices .
- Target: Programming languages differ from natural languages in that natural languages are only used for interaction between people, while programming languages also allow humans to communicate instructions to machines. In some cases, programming languages are used by one program or machine to program another; PostScript source code, for example, is frequently generated programmatically to control a computer printer or display.
- Constructs: Programming languages may contain constructs for defining and manipulating data structures or for controlling the flow of execution.
- Expressive power: The theory of computation classifies languages by the computations they can express. All Turing complete languages can implement the same algorithms. ANSI/ISO SQL and Charity are examples of languages that are not Turing complete yet often called programming languages.
Non-computational languages, such as
markup languages like
HTML or formal grammars like BNF, are usually not considered programming languages; however, informal usage sometimes includes them.
Purpose
A prominent purpose of programming languages is to provide instructions to a computer. As such, 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, computers do exactly what they are told to do, and cannot understand the code the programmer "intended" to write. The combination of the language definition, the program, and the program's inputs must fully specify the external behavior that occurs when the program is executed.
Many languages have been designed from scratch, altered to meet new needs, combined with other languages, and eventually fallen into disuse. Although there have been attempts to design one "universal" computer language that serves all purposes, all of them have failed to be accepted in this role. The need for diverse computer languages arises from the diversity of contexts in which languages are used:
- Programs range from tiny scripts written by individual hobbyists to huge systems written by hundreds of programmers.
- Programmers range in expertise from novices who need simplicity above all else, to experts who may be comfortable with considerable complexity.
- Programs must balance speed, size, and simplicity on systems ranging from microcontrollers to supercomputers.
- Programs may be written once and not change for generations, or they may undergo nearly constant modification.
- Finally, programmers may simply differ in their tastes: they may be accustomed to discussing problems and expressing them in a particular language.
One common trend in the development of programming languages has been to add more ability to solve problems using a higher level of
abstraction. The earliest programming languages were tied very closely to the underlying hardware of the computer. As new programming languages have developed, features have been added that let programmers express ideas that are more removed from simple translation into underlying hardware instructions. Because programmers are less tied to the needs of the computer, their programs can do more computing with less effort from the programmer. This lets them write more programs in the same amount of time.
Natural language processors have 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 Dijkstra took the position that the use of a formal language is essential to prevent the introduction of meaningless constructs, and dismissed natural language programming as "foolish." Alan Perlis was similarly dismissive of the idea.
Elements
Syntax
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. On the other hand, there are some programming languages which are more graphical in nature, using spatial 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. Since most languages are textual, this article discusses textual syntax.
Programming language syntax is usually defined using a combination of regular expressions and Backus-Naur Form . Below is a simple grammar, based on Lisp:
expression = atom | list
atom = number | symbol
number = [+-]?['0'-'9']+
symbol = ['A'-'Z''a'-'z'].*
list =
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 characters ; 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', '
', '
'
Not all syntactically correct programs are semantically correct. Many syntactically correct programs are nonetheless ill-formed, per the language's rules; and may 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:
- "Colorless green ideas sleep furiously." is grammatically well-formed but has no generally accepted meaning.
- "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 an operation that is not semantically defined :
complex *p = NULL;
complex abs_p = sqrt ;
Type system
A type system defines how a programming language classifies values and expressions into
types, how it can manipulate those types and how they interact. This generally includes a description of the
data structures that can be constructed in the language. The design and study of type systems using formal mathematics is known as
type theory.
Internally, all data in modern digital computers are stored simply as zeros or ones . The data typically represent information in the real world such as names, bank accounts and measurements, so the low-level binary data are organized by programming languages into these high-level concepts as data types. There are also more abstract types whose purpose is just to warn the programmer about semantically meaningless statements or verify safety properties of programs.
Languages can be classified with respect to their type systems.
Typed vs untyped languages
A language is
typed if operations defined for one data type cannot be performed on values of another data type. For example, "text" is a string. In most programming languages, dividing a number by a string has no meaning. Most modern programming languages will therefore reject any program attempting to perform such an operation. In some languages, the meaningless operation will be detected when the program is compiled , and rejected by the compiler, while in others, it will be detected when the program is run , resulting in a runtime exception.
By opposition, an
untyped language, such as most assembly languages, allows any operation to be performed on any data type.
Consolidation and growth
The 1980s were years of relative consolidation.
C++ combined object-oriented and systems programming. The United States government standardized
Ada, a systems programming language intended for use by defense contractors. In Japan and elsewhere, vast sums were spent investigating so-called "fifth generation" languages that incorporated logic programming constructs. The functional languages community moved to standardize ML and Lisp. Rather than inventing new paradigms, all of these movements elaborated upon the ideas invented in the previous decade.
One important trend in language design during the 1980s was an increased focus on programming for large-scale systems through the use of
modules, or large-scale organizational units of code. Modula-2, Ada, and ML all developed notable module systems in the 1980s. Module systems were often wedded to generic programming constructs.
The rapid growth of the
Internet in the mid-1990's created opportunities for new languages.
Perl, originally a Unix scripting tool, became common in dynamic
Web sites.
Java came to be used for server-side programming. These developments were not fundamentally novel, rather they were refinements to existing languages and paradigms.
Programming language evolution continues, in both industry and research. Current directions include security and reliability verification, new kinds of modularity , database integration, and the "
Free and Open Source Software" development philosophy.
Taxonomies
There is no overarching classification scheme for programming languages. Any given programming language does not usually have a single ancestor language. Languages commonly arise by combining the elements of several predecessor languages with new ideas in circulation at the time. Ideas that originate in one language will diffuse throughout a family of related languages, and then leap suddenly across familial gaps to appear in an entirely different family.
The task is further complicated by the fact that languages can be classified along multiple axes. For example, Java is both an object-oriented language and a concurrent language .
Python is an object-oriented scripting language.
In broad strokes, programming languages divide into
programming paradigms and a classification by
intended domain of use. Paradigms include procedural programming, object-oriented programming, functional programming, and logic programming; some languages are hybrids of paradigms or multi-paradigmatic. An assembly language is not so much a paradigm as a direct model of an underlying machine architecture. By purpose, programming languages might be considered general purpose, system programming languages, scripting languages, domain-specific languages, or concurrent/distributed languages . Some general purpose languages were designed largely with educational goals.
See also
References
Further reading
- David Gelernter, Suresh Jagannathan: Programming Linguistics, The MIT Press 1990.
- Samuel N. Kamin: Programming Languages: An Interpreter-Based Approach, Addison-Wesley 1990.
- Shriram Krishnamurthi: Programming Languages: Application and Interpretation, .
- Burce J. MacLennan: Principles of Programming Languages, Harcourt Brace Jovanovich 1987.
- John C. Mitchell: Concepts in Programming Languages, Cambridge University Press 2002.
- Benjamin C. Pierce: Types and Programming Languages, The MIT Press 2002.
- Ravi Sethi: Programming Languages: Concepts and Constructs, 2nd ed., Addison-Wesley 1996.
- Richard L. Wexelblat : History of Programming Languages, Academic Press 1981.
External links
- - a collection of implementations in many languages