22

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?

hippietrail
  • 263
  • 3
  • 10
Lucas
  • 403
  • 5
  • 14
  • 5
    Do you mean other than being Turing complete? – Manoj R Dec 28 '12 at 08:01
  • 1
    @ManojR Not all Turing complete languages are considered programming languages, for example XSLT. – yannis Dec 28 '12 at 08:04
  • Re closing, see the Q/A in meta at http://meta.programmers.stackexchange.com/q/5397/70298 – miraculixx Dec 29 '12 at 08:19
  • 1
    Great edit @gnat, thanks. Question re-opened, obsolete comments removed. – yannis Dec 29 '12 at 10:38
  • 1
    @YannisRizos I just copied clarification given by OP [in comments](http://programmers.stackexchange.com/questions/180824/ive-been-told-html-is-a-markup-language-c-is-a-programming-language-what-co#comment346610_180824 "here"). Wonder why so many users put important stuff about their posts in comments, instead of editing; myself I almost always edit my posts in cases like that – gnat Dec 29 '12 at 10:41
  • http://stackoverflow.com/a/5239256/293147 – SK-logic Jan 01 '13 at 23:08
  • related (possibly a duplicate): [Programming Language vs Markup Language vs Scripting Language](http://programmers.stackexchange.com/questions/241104/programming-language-vs-markup-language-vs-scripting-language) – gnat Apr 04 '16 at 15:24

4 Answers4

45

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:

  1. Some non Turing complete languages are considered programming languages, for example Charity.
  2. Some languages that are not generally considered programming languages are Turing complete, for example XSLT.
  3. 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.

Jimmy Hoffa
  • 16,039
  • 3
  • 69
  • 80
yannis
  • 39,547
  • 40
  • 183
  • 216
  • 6
    Could you elaborate on the "XSLT not considered a programming language". I never have seen this and IMO I would even question somebody's knowledge or competence with PLs when uttering this. I can't even think of any reason why XSLT shouldn't be regarded a PL (XSLT might be a mild case of turing tarpit but that's another issue). – bhaak Dec 29 '12 at 13:15
  • @bhaak I'm not saying it _shouldn't_ be considered a programming language. Data transformation languages are not generally thought of as programming languages, which says absolutely nothing at all for if they are, or aren't programming languages. I've seen business logic in XSLT and I personally consider it a programming language. But I probably wouldn't, if I haven't first seen it at work. In any case, who cares? – yannis Dec 29 '12 at 13:39
  • You could add a sentence or two on what it means to be turing complete. – phant0m Dec 29 '12 at 19:55
  • @phant0m [What makes a language Turing-complete?](http://programmers.stackexchange.com/questions/132385/what-makes-a-language-turing-complete) – yannis Dec 29 '12 at 20:20
  • @think123 I don't think I can give a simpler definition than the one in Wikipedia, and I've already linked to the relevant article in the answer. – yannis Dec 29 '12 at 23:41
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.

Carson63000
  • 10,510
  • 1
  • 28
  • 50
  • But now you are limiting "programming languages" to "general purpose programming languages". The latter is what people usually means when they say "programming language", but pursuing exactly what the defining characteristics are of a "programming language" also has its point in understanding what programming languages are, how they work, and what their limitations are. For example, any skilled programmer has to recognize the halting problem when they encounter it, which would be difficult without studying the theoretical boundaries of programming languages. – JesperE Dec 28 '12 at 21:39
  • @JesperE: I'm happy to limit my "I know it when I see it" judgement to programming languages that are at least fairly general in purpose. Also I disagree that "any skilled programmer" needs any knowledge of the halting problem - I know that my knowledge of it from my formal computer science education has never been of any relevance to me in nearly two decades of professional development. – Carson63000 Dec 29 '12 at 05:45
  • 1
    If you haven't had to bring it up, that's probably good. That doesn't mean that it is not important to know. You don't judge the quality of your seatbelt by how often it came to actual use, do you? – JesperE Dec 29 '12 at 10:16
  • By your heuristic, is elisp a programming language? – Brian Apr 26 '13 at 18:15
  • @Brian: interesting one! I guess I've always simply thought of elisp as an implementation of Lisp, which clearly is a programming language, even though this *particular* implementation is much more specific in its scope of purpose. – Carson63000 Apr 27 '13 at 03:14
  • Justice Stewart's reasoning was something like the following: "Pornography is what would be offensive to a man of average sensuality (un homme moyens sensual). I am such a man. Therefore I know it when I see it." Do programmers have such an "average" sensibility? – Tom Au Mar 14 '15 at 19:26
  • @TomAu I think so. I think you'd get a lot more arguments about whether something is pornography or erotic art than you would about whether something is a programming language or not. I'm not aware of any formal research though. :-) – Carson63000 Mar 15 '15 at 22:13
2

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.

hekimgil
  • 21
  • 1
0

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.

Radu Potop
  • 655
  • 5
  • 5