I've been in a recent set of videos that we've done,
related to HTML, I really have taken a severe beating in the latest one that
I'm a disgrace to Full Professors as I don't know what a programming language is
and how it differs from a markup language. And my attitude is going to be:
"Well I stand by what I say".
HTML is a very restricted form of programming language, in my view, so we
need to justify that.
And I need to say at the outset that you don't need to see all the previous HTML
videos in order to understand this one, because it really comes down to
something that's actually very fundamental. In the end it comes down to
two different styles of programming language that are interrelated that you
can differentiate, in a way, between them. And when does one merge into the other? And
these two ways of doing programming are known in the trade, generically, as either
the imperative style or the dclarative.
Now the one that most of you will be the more familiar with is the imperative so
we'll do that first.
This is really just programming as you and I understand it you take your
language of your choice
Assembler, Java, C, Basic, whatever and you are required to give a detailed
specification of how you are going to do this problem. And, as we know, this
detailed specification might be simple arithmetic programming statements;
it might require going round things in loops;
it would certainly require taking decisions. So it will have 'if' statements
inside it.
So, if you like, ordinary straightforward detailed nuts-and-bolts programming is
in an imperative style, because you have to say how you are going to solve
the problem. I'll put "How" in quotes here saying that leads you to 'if', 'for',
arithmetic statements, whatever you need.
>> SEAN: So this is setting out how you are going to do something. If this button is pressed
then do this?
>> DFB: Yes! Yes! And the vast majority of programs that most people think of, in
terms of programming, are done in this style.
Now what about declarative then? Well 'declarative' - it's a more functional style
of programming, where the interpreter for your language does the details and
actually one style can merge into another And I've got a very good example of my
own and we've done it on Computerphile. I wrote a program to do the Ackermann
function. I think it's my biggest hit so far - that particular video. And within the
function 'ackermann' we saw program statements, we saw use of recursion,
we saw 'ackermann' calling 'ackermann' and all this kind of stuff. And finally
returning and delivering back an answer.
However, back in the main program where I call up 'ackermann'
with certain arguments and I call up the 'ackermann function' as the arguments ....
I don't worry about the implementation details of 'ackermann'
I just call it up - at the end of a big printf statement as i recall. I say
declaratively "Give me 'ackermann' -
do it for me! I forgot the details of how I did it". Many of you know this. The whole
idea of writing your own library full of functions for a particular job is that
you can then work more abstractly. and at a higher level. You can say "I wrote
those 20 years ago. I've forgotten how I did them. But it doesn't matter. Do me 'ackermann' with
parameters "thing" and "thing" -- something like that.
So you see the one can merge into the other as you take a more functional
approach. You could argue, loosely, every time you use a library of functions that
you bought in from somewhere then you are becoming more declarative in the way
that you use it.
So the point about declarative is you don't have to go into the nuts and bolts
details. You just ask for what you want and magically it happens.
Typical examples of real declarative languages are things like Haskell.
what are the trade-offs about this? Well, you could probably say that most of
these declarative languages
don't work on the bare metal, like your C program could do eventually. They are
interpreted, with a layer of software between you and the bare metal. Now that
gives you flexibility because the Haskell interpreter can be basically
ported to all sorts of architectures. Somebody's got to do the hard work but
then you know that if you take the Haskell program along
you can just run it. You don't have to convert it into a binary. It just runs on
the interpretive mode. So it's trade-offs And other things being equal (it's less
true now it used to be) you lose a little bit of efficiency in an
interpreter whereas, y' know, if you refine a thing right down to a hard-core binary
it'll go off like a Maserati,
we hope. And some languages, as we know, have a compromise here. Java started life
as being a portable interpreted system but with a syntax that's really pretty much
like C. But it's notable that now, when you've developed from the Java, there's very
often an option to say 'If you want to compile this and make a real executable
binary of it
yes, you can do that'. But during development you get a lot of flexibility
by just being able to do things and try them out instantly . That then, I hope, has
given you a bit more insight into what the imperative vs. the declarative
approach is. And that's very relevant to discussions of whether
HTML is, or is not, a programming language.
We all know means give me a heading, level one.
Now, of course, I have to show where the stuff that is your heading - the text -
ends. But to me you can say "Look, I'm calling up the function , I'm giving it
the argument
'this is my heading' to be done in h1 style". And is really just
to say, "Oh! by the way, there's no other way I can signify where my text string
ends, It's not semicolon or anything like that".
Conventionally its . So to me,
yes, you can think of that as being a function call in a way.
However, some of you really did hit home a bit more accurately, I think, when you
said "It can't be a programming language,
really, because it's not Turing Complete.
Now that is a topic - I'm sorry I hate doing cliffhangers, you know I do! -
that's a topic that we have mentioned from time to time but it's big enough
that we need to do a separate video, really, on that, It's perfectly correct that
HTML could never be thought of as a full-blown programming language.
It can't do 'if' statements in its raw vanilla form!
There's no way inside HTML that you can say "Give me a megabyte more space to
work with". It's just not part of the language.
Somebody has pointed out, I think, that HTML with CSS does become a very
powerful Turing-Complete language but you wouldn't want to use it.
It's not general purpose - that's another thing. It's really is a question of "Is it
imperative; is it declarative?" This is declarative but is it general purpose?
No, this is really for programming Web pages.
That's the way I think of it and also, like I say, it's not Turing Complete, but
you can certainly argue that anything that takes tags as if they were function
calls and interprets them and does them for you is, in some restricted sense, in my
view anyway,
a programming language.