My programming friends are always telling me that HTML is a markup language and C++ is a programming language. When I ask them what’s the difference, they never give me a reasonable answer.
What could make one call C++ a programming language, and HTML not?
7
A programming language is a notation designed to pass instructions to a machine. By that definition both C++ and HTML are programming languages, as was the notation Joseph Marie Jacquard used in 1801 to program his looms.
However with the proliferation of languages that are used to structure and/or describe data, the definition of a programming language shifted to include only languages that are capable of expressing algorithms. This is the more common definition today and it excludes languages like HTML or XML.
At the heart of the current definition is the concept of Turing completeness. Most programming languages are Turing complete, and Turing completeness is often quoted as the one critical trait that separates a programming language from any other computer language. This is good enough as a general rule of thumb, but not entirely accurate:
- Some non Turing complete languages are considered programming languages, for example Charity.
- Some languages that are not generally considered programming languages are Turing complete, for example XSLT.
- Turing completeness alone doesn’t say much about a language’s usefulness.
Depending on context, you can pick any definition you want.
Edit:
Let it further be known, an implementation of a language does not confer characteristics onto the language itself, for example: A language’s spec may define a turing complete language, someone could implement it haphazardly leaving off turing completeness. This implementation being non-turing complete does not however mean the language itself is not turing complete (rather it likely means that implementation is non-conformant). The details of a language and the details of a particular implementation of a language are to be recognized as separate things, this is why it’s inaccurate to call a language interpreted or compiled etc.
5
The phrase “I know it when I see it” is a colloquial expression by
which a speaker attempts to categorize an observable fact or event,
although the category is subjective or lacks clearly defined
parameters. The phrase was famously used by United States Supreme
Court Justice Potter Stewart to describe his threshold test for
obscenity in Jacobellis v. Ohio (1964).
— “I know it when I see it” Wikipedia article
Like obscenity, I think we all know a programming language when we see one. Clearly the OP does, since you’ve already judged C++ to be a programming language, and HTML not to be one.
So what exactly is the goal of pursuing a formal definition? Yannis has already given a great rundown of why the most popular definition, Turing completeness, is flawed: it leads to categorization which defy the “I know it when I see it” test.
I put it to you that any definition you can come up with will lead to some languages which we all feel are not “programming” languages will be categorized as being so; or to some languages which we all feel are “programming” languages will be categorized as not being so.
Why not just go with your gut? I use a simple heuristic: a programming language is a language whose primary purpose, in my opinion and according to my observations, is to write programs. Not to mark up content. Not to transform XML. To write general purpose programs. I’d rather just know it when I see it than try to nail down a formal definition, and I don’t see any genuine value that can come from attempting such a definition.
7
Markup languages mainly deal with how the information is displayed and they generally lack in the programming infrastructure of variables, math, comparison, decision making (if … then), loops (for, while), etc.
HTML by itself is static; that is, much like a word-processor, it is meant to present the information as it is. Only with the addition of some sort of programming languages (usually scripting languages like JavaScript, PHP, etc) can the HTML web pages can have a “changing” content. The scripting languages provide the “programming” possibilities with variables, math, comparisons, decision making, loops, etc.
HTML is a declarative language. It doesn’t do much on its own, it just describes a document and its content (using tags that have a semantic meaning).
C++ on the other hand does something. It does define functions and classes, but it also describes how these functions should work together, how their inputs and outputs are tied together in a meaningful way and how the application should run as a whole.