September 21, 2010

Thoughts on HTML, computer programs, and programming languages

I would like to start this post off by saying that emotionally I agree with the sentiment that HTML is not a programming language. Intellectually, however, my position is that HTML is a programming language.

My argument for HTML as a programming language is very abstract, and to put it simply: programming languages are used to express instructions to the computer on what to do. HTML instructs the computer on how to display content, therefore HTML is a programming language. Against this argument are the following, which can be encountered on any number of programming websites.

The most common argument against HTML being a programming language is that it describes itself as a markup language, as evident by the M in HTML. I find this argument wanting on 2 fronts: a) it implicitly assumes that a markup language can not be a programming language. TEX is a good example of a language which 99% of the time is used for markup, and the other 1% for programming; b) this argument is superficial. It implies if I was to simply rename HTML to HTPL, hypertext programming language, then *poof* now it is a programming language without having changed any of its characteristics. A rose by any other name...

A better argument is that HTML doesn't have control structures, whereas programming languages do. Suppose we accept this argument, which implicitly requires programming languages to support control structures. Consider a strict subset of LOGO, called miniLOGO that contains only the turtle graphics part of LOGO and nothing else - no loops, no conditionals, no control structures. By the definition we have assumed here, miniLOGO isn't a programming language. Now suppose you write a program in miniLOGO to draw "hello world"  on the screen, what have you written? I (and most people) say it is a program. This then presents a problem: you should not be able to write a program with a not-programming-language. At least it is a problem for me.

Suppose now you say no, the miniLOGO hello world isn't a program, and you give one of two reasons - that it doesn't contain control structures or that it wasn't written in a programming language. The first reason implicitly defines all programs as those containing control structures. I can not accept this reason because you can make a non-program a program by injecting a control structure with no side effect, and it is no less absurd and no more useful than the accepting HTML as a programming language. Not to mention the millions of introductory programming texts that will need to be rewritten so "hello world" contains an unecessary control structure. (There are those who will then say: there ARE control structures, they are just a few levels of abstractions down. Well there are similar control structures in a browser. We do not worry about the rest of the abstraction stack, only the top of it).

For the second reason, consider what happens if I write the same program in full is-a-programming-language LOGO. Now it is a program by the virtue of having been written in a programming language, which brings us to an uncomfortable place: now we two things which are absolutely identical, but one is a program and one isn't by virtue of their parentage. Accepting this position is no more absurd than accepting that HTML is a programming language.

The final argument I will discuss is that my definition is such a generic definition just about anything is a programming language, therefore that definition is next to useless. This I agree with. However as I have (hopefully) demonstrated, it isn't easy to come up with a definition of what is a programming language (or in fact what is a program) that isn't contradictory or would invalidate millions of simple programs around the world.

I am still giving this issue thought, but until I am a more learned person in CS and possibly philosophy, my choice is between a definition of programming languages with low discriminatory powers, or ones which are fickle and contradictory.

HTML-is-a-programming-language, I choose you!

Cheers,
Steve