What is a programming language
I get into debates with people every so often about what a programming language is, so I thought I'd explain it in writing for maximum clarity.
A programming language is a language that is designed to write programs in.
There's three important ideas embedded in this definition.
- A programming language is a language
- A programming language can write (specify) programs
- A programming language is designed to do so.
Of these three criteria, the one I find the most confusion over is 2, mostly because sometimes it's not so easy to say what a program itself is, nor its relationship to a programming language.
What's a program?
A computer program is something that takes various inputs (mouse/keyboard, text, files, et cetera) and produces various outputs (visuals, audio, text, files, et cetera) from those inputs by following some sort of procedure. This procedure is usually specified by writing it out in a programming language, hence the close relationship between programming language and program.
+---------+
| |
Inputs -> | Program | -> Outputs
| |
+----⦀----+
⦀
Behavior specified by p.l.
Thus, a programming language is a language that describes how to produce various outputs given certain inputs.
This is why HTML (Hyper Text Markup Language) is not a programming language as HTML doesn't describe how to produce outputs from inputs. Rather, HTML describes the content to display in a web page, and web page content is not a program.
So why is it so easy to think that HTML is a programming language? Well, the relationship between interpreters/compiler and source code
Inputs
v
+--------------+ +---------+
| Compiler | | |
Source Code -> | or | -> | Program |
| Interpreter | | |
+--------------+ +---------+
v
Outputs
looks a lot like the relationship between HTML and the browser.
Mouse
v
+---------+ +----------+
| | | |
HTML code -> | Browser | -> | Web Page |
| | | |
+---------+ +----------+
v
Screen
Since the mouse provides some input, and the screen provides output, it seems fair to say that a web page is a very simplistic program of sorts. However, recall that the relationship between program and programming language is one of specification: the source code written in a programming language should specify the behavior of a program, and this isn't the case with HTML. Sure, HTML specifies the content that the program puts out, but the program's behavior is determined by the browser.
Thus, a better diagram for the relationship would be
+---------+
HTML code -> | |
| Browser | -> Screen
Mouse -> | |
+---------+
as it emphasizes that the browser is doing all the computation, not the HTML.
Language & Design
With a clearer idea of what it means for a language to specify programs, the other crucial part of the definition of a programming language is the design aspect: a programming language not only can specify programs, but a programming language is designed to specify programs. This is important part of the definition because many different tools canbe used to write/specify programs, but that doesn't automatically make those tools programming languages.
For instance, one of the common arguments is that a language is a programming language if it's Turing complete (able to simulate a Turing machine). This demonstrates that the language is capable of performing any general computation, but capability alone isn't the deciding factor. As example, it has been shown that Power Point animations are Turing complete, yet no one commonly thinks of Power Point animations as a programming language.
The difference Python and Power Point animations, is that Power Point animations weren't designed to be used to write programs, though they certain can do so. While that difference may seem trivial, it doesn't really make sense to consider well designed programming languages equivalent to ad hoc methods of constructing programs. Thus the fact programming languages were designed to write programs with gives a nice, objective difference between what is and isn't a programming language without conceding to popular opinion. As long as it's designed to create programs and is capable of doing so, we can consider a language a programming language.