Where HTML beats C? – Computerphile

Where HTML beats C? – Computerphile

You take great care when you’re buying
an app. to make sure it’s good and it’s not going to ruin your machine and does
exactly what you want. HTML is the ultimate example of what
troubles you get into if you are promiscuous, right [laughs]? And you are
promiscuous why? Because part of what HTML
does is you have to visit other people’s Web sites. And you have
to execute – not your code that you wrote – other people’s code. HTML it’s an interpreted system. The customers
want instant gratification and you’ve got to get cracking. Speed is of the essence. I
think the nub of what we’re trying to get at is this: HTML seems to be able to
tolerate your mistakes. But for those of you who know a programming language —
Basic, C or whatever, you know they will NOT tolerate your mistakes. They won’t
interpret for you, they won’t compile a program for you, unless it’s correct. So
how does this difference come about? If HTML is a language – it’s getting executed – what
is it about it that makes it easy to be tolerant? And on the face of it, yes, it’s
wonderful – it seems to put my errors right! Perhaps we could start off with
our good old friend the paragraph

And I’m going to just put a piece of
text in here which says “Hello Sean”. And even though I absolutely don’t have to do it
nevertheless I want to do it – I want to close off the paragraph. And then I’m going to open
up another one, straightaway afterwards, “Goodbye Dave”. Once again we close off with a

. You’ll all understand that this is a classic use of paragraphs. You put them
in sequence you have first paragraph, second
paragraph, third paragraph. All that kind of thing. Does it mean anything
and does it look any different and does it do any different if I start messing
about and saying: “I’m not going to sequence them, I’m going to fit the second paragraph
inside the first so it’s nested, as we say. It forms a hierarchy. It’s a para
within a para. You can see the difference I’ve opened up a paragraph and I’ve said “Hello
Sean”. I’ve then opened up another paragraph and I’ve said “This is a nest” just
to hammer it home that the inner one really is sitting inside the outer one. And then I
dutifully closed them both off. You might think: “Oh! I know what it will do. I might get
‘Hello Sean’ and then the phrase “This is a nest” will be tabbed in and indented. Maybe
that’s what it does. So I’ve tried this out in my own Firefox browser. And, believe you me, it
doesn’t crash; it it just treats it exactly as if it was sequential
paragraphs. There’s no sign of nesting or anything. So if we develop these a little
bit further now, we could say “OK do the

‘Hello Sean’ do another

‘Goodbye Dave’
>>Sean: So you’re omitting the closing bit is that right?
>>DFB: I’m ommitting the closing of the
paragraphs. Is that acceptable to HTML? Yes it is. Nothing was gonna to fault you for missing

. And that, if you type that in, will look the same as that. It wants to
put the end-tags in and obviously, in some sense, it does. But what’s its rule and,
here we go, it probably won’t do what you want to do.
It does what it finds convenient and what it finds convenient is the following rule:
It says “I am going to assume, if you give me a second

and I’m already inside the
first one I’ll just close the first one off”. How would the browser cope if I sometimes
put my

in and sometimes didn’t? And the answer is that it will always, as far
as I know, assume that you want a sequence and that is what it will impose on
you. What it comes down to is a sort
of informal theorem, something like the following. If you’re
trying to be very clever and mend somebody’s incorrect program then the
problem is that if you have a structure that can be ‘a sequence of’, or it can be
‘a nest of, ‘or it can be any any combination you could have ‘a sequence of nests’ or a
‘nest of sequences’. But if you once start saying they can both co-exist
— nesting, sequencing — then you must put your end-tags in, if you want to be unambiguous.
Otherwise how can it be repaired? So in other words if both
possibilities are possible then you can’t have smart behaviour because it cannot
know how to repair it correctly. And what HTML is doing is — it’s not solving the
insoluble — it’s saying I have one view of the world and I’m going to
impose it on you and I am NOT going to try and be clever. Now that, of course, is
a luxury that HTML has. It basically says
“I keep things simple. I like things to be more or less
sequential with the minimum of this embedding, y’ know and all that — and that’s why I can
get away with murder. Now for those of you that have written a program and know
that you compile it, or even you interpret it – Oh! boy — it’s not going to
try and mend your bad program for you! Why is it that things are so much more complicated/ Well, the answer is you can do more with
these languages and you will want to do more. Let me just invent a little piece of
pseudo-code and I’ll let you fill this in, in either Basic, or C, or Java
or whatever turns you on: printf(“Hello Seann”) C programmers will know that if you
want a new line at the end of that, which you do – you’d better put a n at the end.
We’re going round the stuff inside this block, which is a very simple block — it’s just got
a single print statement in it — so what we’ll get is “Hello Sean”, “Hello Sean”, “Hello Sean”,
“Hello Sean”. ten times. Then I do another loop that
goes around 10 times: “Goodbye Daven”; Let’s hope this really would compile ! You can all see what’s going to happen when you
execute this. I’m goingto get “Hello Sean”
“Hello Sean” ten times and “Goodbye Dave”, “Goodbye Dave”, “Goodbye Dave”,
Goodbye Dave” ten times. So that is what happens
when you have a sequence of blocks. But by comparison
with “paragraph” in HTML can you, in programming languages, have nested
blocks? You bet you can! Now I’m going
to say: loop around 10 times on the following:
printf(“Hello Seann”) but now look at what I’m going to do I’m now not going to close off that block.
I’m going to nest another loop block inside it: “Goodbye Dave”. Now let’s make sure
our brackets match. I’ve opened up one, I’ve opened up two. I’ve closed this one, I must close
that one. I hope you can all see and understand what I’m trying to do here.
I’m trying to do a loop within a loop They are nested like sort of Russian dolls,
one inside the other, but the effect of this is completely different to the one
I did previously. Here what’s going to happen is the outermost one goes around 10
times and every time it goes around it does a “Hello Sean”. But every time it does a
“Hello Sean” it then goes into a nested inner loop that does ten “Goodbye Dave”s. So for
every one “Hello Sean” I print out, I’m now getting ten “Goodbye Dave”s. Net result; I will
end up with a hundred “Goodbye Dave”s interleaved between ten “Hello Sean”s
whereas, in the earlier case, I had 20 print outs. I had ten “Hello Sean”s followed
by ten “Goodbye Dave”s. Lots of students have said to me over the years: “The C compiler is
so clever, why can’t it put my programs right for me?” And the answer is if you omit your
end-tags, how can it know whether you want this one, or this one? They’re both
equally valid. This, then, is the absolute fundamental conundrum: can you
unambiguously put back the close curly braces if users omit them? No you can’t
because you’ve got to work out: do they want a sequence, a nest, a nest of
sequences? There’s all sorts of places to put back the brackets and they have all
sorts of different effects. And that is why C, Java Basic, whatever, have to be ‘theological’ and
start laying down the law to you “Brackets mismatch” or whatever, whenever you
miss them out. The reason — let’s say it again — why HTML can be so tolerant is because
it’s so much simpler than C. It is a programming language; it is an execution
environment, but it’s not been built to support deeply-nested hierarchical
structures. So although it seems to be tolerant, and although it seems to be
correcting your program, you’ve got to remember it isn’t really doing the
impossible. It’s imposing a model on you and hoping that the visual effect of what
it does is so stunning that you won’t notice that it’s not quite done what you
hoped it would do.


  1. This is not comparing apples to oranges, this is comparing apples to solar systems, HTML is NOT a programming language.

  2. HTML is not a programming language, period. Comparing a markup language with no logical constructs to C is comparing apples and oranges. It's like using assembly instead of MS Word to write and format your thesis, or on the other hand, to use MS Word to develop a computer game. That makes no sense. The title of the video is a clickbat and it mostly deals with nitpicks about grammar of C vs HTML.

  3. so in other words, if both possibilities are possible, @4:40
    for anyone that has compiled a program, or interpreted it… @5:10

  4. "html IS a programming language but it can't handle deeply nested theoretical hierarchical structures"

  5. 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635342207222582848864815845602850601684273945226746767889525213852254995466672782398645659611635488623057745649803559363456817432411251507606947945109659609402522887971089314566913686722874894056010150330861792868092087476091782493858900971490967598526136554978189312978482168299894872265880485756401427047755513237964145152374623436454285844479526586782105114135473573952311342716610213596953623144295248493718711014576540359027993440374200731057853906219838744780847848968332144571386875194350643021845319104848100537061468067491927819119793995206141966342875444064374512371819217999839101591956181467514269123974894090718649423196156794520809514655022523160388193014209376213785595663893778708303906979207734672218256259966150142150306803844773454920260541466592520149744285073251866600213243408819071048633173464965145390579626856100550810665879699816357473638405257145910289706414011097120628043903975951567715770042033786993600723055876317635942187312514712053292819182618612586732157919841484882916447060957527069572209175671167229109816909152801735067127485832228718352093539657251210835791513698820914442100675103346711031412671113699086585163983150197016515116851714376576183515565088490998985998238734552833163550764791853589322618548963213293308985706420467525907091548141654985946163718027098199430992448895757128289059232332609729971208443357326548938239119325974636673058360414281388303203824903758985243744170291327656180937734440307074692112019130203303801976211011004492932151608424448596376698389522868478312355265821314495768572624334418930396864262434107732269780280731891544110104468232527162010526522721116603966655730925471105578537634668206531098965269186205647693125705863566201855810072936065987648611791045334885034611365768675324944166803962657978771855608455296541266540853061434443185867697514566140680070023787765913440171274947042056223053899456131407112700040785473326993908145466464588079727082668306343285878569830523580893306575740679545716377525420211495576158140025012622859413021647155097925923099079654737612551765675135751782966645477917450112996148903046399471329621073404375189573596145890193897131117904297828564750320319869151402870808599048010941214722131794764777262241425485454033215718530614228813758504306332175182979866223717215916077166925474873898665494945011465406284336639379003976926567214638530673609657120918076383271664162748888007869256029022847210403172118608204190004229661711963779213375751149595015660496318629472654736425230817703675159067350235072835405670403867435136222247715891504953098444893330963408780769325993978054193414473774418426312986080998886874132604721569516239658645730216315981931951673538129741677294786724229246543668009806769282382806899640048243540370141631496589794092432378969070697794223625082216889573837986230015937764716512289357860158816175578297352334460428151262720373431465319777741603199066554187639792933441952154134189948544473456738316249934191318148092777710386387734317720754565453220777092120190516609628049092636019759882816133231666365286193266863360627356763035447762803504507772355471058595487027908143562401451718062464362679456127531813407833033625423278394497538243720583531147711992606381334677687969597030983391307710987040859133746414428227726346594704745878477872019277152807317679077071572134447306057007334924369311383504931631284042512192565179806941135280131470130478164378851852909285452011658393419656213491434159562586586557055269049652098580338507224264829397285847831630577775606888764462482468579260395352773480304802900587607582510474709164396136267604492562742042083208566119062545433721315359584506877246029016187667952406163425225771954291629919306455377991403734043287526288896399587947572917464263574552540790914513571113694109119393251910760208252026187985318877058429725916778131496990090192116971737278476847268608490033770242429165130050051683233643503895170298939223345172201381280696501178440874519601212285993716231301711444846409038906449544400619869075485160263275052983491874078668088183385102283345085048608250393021332197155184306354550076682829493041377655279397517546139539846833936383047461199665385815384205685338621867252334028308711232827892125077126294632295639898989358211674562701021835646220134967151881909730381198004973407239610368540664319395097901906996395524530054505806855019567302292191393391856803449039820595510022635353619204199474553859381023439554495977837790237421617271117236434354394782218185286240851400666044332588856986705431547069657474585503323233421073015459405165537906866273337995851156257843229882737231989875714159578111963583300594087306812160287649628674460477464915995054973742562690104903778198683593814657412680492564879855614537234786733039046883834363465537949864192705638729317487233208376011230299113679386270894387993620162951541337142489283072201269014754668476535761647737946752004907571555278196536213239264061601363581559074220202031872776052772190055614842555187925303435139844253223415762336106425063904975008656271095359194658975141310348227693062474353632569160781547818115284366795706110861533150445212747392454494542368288606134084148637767009612071512491404302725386076482363414334623518975766452164137679690314950191085759844239198629164219399490723623464684411739403265918404437805133389452574239950829659122850855582157250310712570126683024029295252201187267675622041542051618416348475651699981161410100299607838690929160302884002691041407928862150784245167090870006992821206604183718065355672525325675328612910424877618258297651579598470356222629348600341587229805349896502262917487882027342092222453398562647669149055628425039127577102840279980663658254889264880254566101729670266407655904290994568150652653053718294127033693137851786090407086671149655834343476933857817113864558736781230145876871266034891390956200993936103102916161528813843790990423174733639480457593149314052976347574811935670911013775172100803155902485309066920376719220332290943346768514221447737939375170344366199104033751117354719185504644902636551281622882446257591633303910722538374218214088350865739177150968288747826569959957449066175834413752239709683408005355984917541738188399944697486762655165827658483588453142775687900290951702835297163445621296404352311760066510124120065975585127617858382920419748442360800719304576189323492292796501987518721272675079812554709589045563579212210333466974992356302549478024901141952123828153091140790738602515227429958180724716259166854513331239480494707911915326734302824418604142636395480004480026704962482017928964766975831832713142517029692348896276684403232609275249603579964692565049368183609003238092934595889706953653494060340216654437558900456328822505452556405644824651518754711962184439658253375438856909411303150952617937800297412076651479394259029896959469955657612186561967337862362561252163208628692221032748892186543648022967807057656151446320469279068212073883778142335628236089632080682224680122482611771858963814091839036736722208883215137556003727983940041529700287830766709444745601345564172543709069793961225714298946715435784687886144458123145935719849225284716050492212424701412147805734551050080190869960330276347870810817545011930714122339086639383395294257869050764310063835198343893415961318543475464955697810382930971646514384070070736041123735998434522516105070270562352660127648483084076118301305279320542746286540360367453286510570658748822569815793678976697422057505968344086973502014102067235850200724522563265134105592401902742162484391403599895353945909440704691209140938700126456001623742880210927645793106579229552498872758461012648369998922569596881592056001016552563756

  6. To every commenter huffing and hawing about html not being a programming language: stop being silly plz

  7. What is this garbage? You could just as well say "where a table beats a bar of soap". They have nothing to do with each other and neither have HTML and C. HTML is an output format, C is a programming language.

  8. Ok, so maybe a <p> is sequenced, but a <div> certainly isn't. So him saying html isn't made for nesting seems a lot short sighted.

  9. HTML is not a programming language. This is like comparing Apples to Zebras. This video should have been two separate videos: One that explains HTML's tolerance, and one that explains why "programming languages" are generally NOT tolerant to mismatched brackets, etc.

  10. I think you contradict yourself. You say C cant close the curly brackets for you because it doesn't know where you want them, but neither does HTML. HTML doesnt know if i want two paragraphs or a nested paragraph. So why can't C do the same and just close off? I'm sure it could do the same guess work and just close off when it comes across the next func definition etc. It could be hella' wrong, but who cares!

  11. This is just… Not true.

    I mean, it's true for exactly unstyled paragraphs that nesting or sequencing look alike. But that's a case that rarely occurs in the real world… Nesting anything with margin, padding, borders, transparent backgrounds, … will not behave the same way.

    It is not HTML "fixing it". The DOM created by his two examples with paragraphs will not be the same.

    Overall I'm sad that he consolidates "errors" with just "syntax errors", which is not just simplistic, but plain wrong and not in accordance with how programming errors are treated in academia. What about all the errors that are not typos, that are syntactically correct but give a result other than the intended?

  12. 7:40 For every one "hello sean", you'd get ten "goodbye dave"s
    I'm going to use that the next time I have to teach someone nested loops.

  13. HTML WAS tolerant, until people tried to add styling to it. Ever seen the horrors of cross-browser compatibility, or the problems with parent/child objects and attribute-inheritance?
    HTML is more like ambiguous math, which force rule-changes like "I prefer addition before multiplying".

    concluding, all real programming languages beat HTML

  14. "those of you who have written a program know that if you interpret it it's not going to try and mend your bad program for you"

    This man obviously isn't aware of the horrors of php. Hopefully he remains as lucky for the rest of his life.

  15. short answer html is not a turing complete language. So it doesn't need to do parse validation as harshly as a regular programming langague.

  16. I think the title did this video a great disservice. The professor never said HTML was better or beat C – he only explained how they are different.

  17. I do not agree on the part where it is said HTML will "assume" your code should be nested or not and execute a bad markup. The fact is, the HTML markup is using tags. The Web consortium defined in an official document how to implement an HTML interpreter, and defines tags as having closing counterparts like p for example. It also defines how a code should be parsed. That is all, if I would create my own browser, if I stop on this reference, your last code without the closing p tags would not be interpretable. What is interesting is that many browser manufacturer implemented, opiniatedly, an automatic code fix to help web page to be executed more often, providing even your code a possible output for the user. This is opiniated and I join your point of view because maybe I did not wanted to do nested but simply sequencial, but Chrome for example has taken the lead on this and is automatically closing tags if they are missing. I also agree that this is a lack of security and a code could not be executed the way the developer intended to. Just wanted to clarify this because I felt we were mixing oranges and apples here's, C code cannot tolerate incorrect code, so does HTML, this is only a sugar feature that browser all have implemented to increase the engagement at the cost of consistency (and frankly speaking, with all our fancy IDE, mistakes on tags are heavily avoided, thanks to real time l'inter).

  18. If C becomes as you say "more tolerant", then it will eventually be a lot harder for you to debug your program since it's no longer gonna be consistent with the rules and syntax.
    I personally think we should make languages as simple to learn as we can, but can't rely on them to correct all of our mistakes just because we're too lazy to learn or to practice.

  19. There could be way for C to atomatically correct some mistakes. For example omiting semicolon after some commands. In most cases it could just put it after calling a void function. But there is a but. It can't be 100% sure what the programmer meant, and as it can change how the program works entirely, it does not let it happen. When the browser interprets the HTML code there is no real risk in inaccuracy, maybe it just won't look that way it was intendd, but in most cases it just corrects well. However in XHTML, where the specification of the language is as strict as with XML, it will throw an error.

  20. Yes, but why can't it figure out that, if it expexts a semi-colon, to just add the freaking semi colon and see what happens

  21. I disagree. HTML doesn't get away with this kind of shenanigans any more than C… C could try to silently "fix" your missing brackets as well… I mean it doesn't, but nothing prevents it from doing so. It would surely be a very bad idea but so is this "feature" of HTML!

  22. Also if you break the HTML rule, the interpretter of html tries to fix it for you, because of the C, which is why C or c++ was more helpful and fixed your mistake,

    Which lives in the browser

  23. C'est bien pour apprendre l'anglais ! Ce qu'il dit n'est pas trop vite, et on comprend, même pour un Français comme moi 🙂

  24. Theoretically, one could write a browser that enfoteces W3C standards to the point that incorrectly formatted HTML would not run. On the other end, one could write a C compiler that made logical assumptions about simple things like closing curly braces. It isn't HTML itself that allows for those sort of mistakes.

  25. <DIV> tags can be nested, <P> tags will be sequential within each <DIV> and <P> tags will be terminated by <DIV> tags.

  26. Oh, come' on! Compare HTML with a programming language doesn't make any sense! HTML stands for Hypertext Markup Language, which means it isn't a programing language but a markup language!

  27. I don’t know if I’d agree that this happens because html is not built for nesting and complexity — the entire document structure is rendered as one big n-ary tree. Rather I think the reason why HTML can be so tolerant, at least in the example given, is because of the semantic ideas that are part of the <p> tag. Simple by using the tag, you’ve already given the interpreter a lot of information about what you’re trying to do, in a way that you haven’t if you put one for loop after another without specifying the relationship between them.

  28. At the beginning of the book The C Programing Language it says, “C assumes the programmer knows best.” Which is exactly the case here.

  29. C deliberately doesn't correct your code so that you don't realise that the compiler is aware… until it's too late.

  30. The example would work better with <div>. The HTML specification is clear about <p> tags: you cannot nest them. There is a clear reason for the browser making a silent assumption. Edge cases were interpreted differently in different browsers thus causing mayhem when the the html was rendered on screen. In short HTML has the same problems as other markup and programming langauges.

  31. I wish he would have made at least a passing reference to HTML lists, which can be nested, and need to be structured appropriately. Although I suppose if you structure them inappropriately the output will just look weird, but the page will still render.

  32. HTML is not a language in the same sense as C/C++, Delphi etc — but rather a markup language, meaning that it allows quick layout and design.
    Javascript came along, and while JS was a joke only 15 years ago – its infrastructure has been evolved so it's "almost" a real programming language now.
    But its ultimately with WebAssembly that you will see "real" coding for the web platform.
    Before you run off to refute this, I love JS. I make compilers for a living and have spent decades in that field.
    But you cannot place JS side-by-side with C, because JS is not an archetypical language.
    There are presently only 3 archetypical languages: assembly, C and pascal.
    These are the languages you use to make all the other languages, which are called optimistic languages.
    They are optimistic because they are built expecting a level of infrastructure. A C program can be compiled to run off the boot-block.
    C and Pascal require no OS when you strip it down. You cant write a "real" kernel in JS, because JSVM expects a huge amount of dependencies to be present

  33. HTML is an interpreted language
    C is a compiled language.

    For example, let's take the interpreted language called BASIC
    Lets write a BASIC program with syntax error at line 10, for instance.
    You can still run the program.
    And it does execute till line 9 and then crashes.
    That's how HTML works. Only that it does not crash because it's not an executable. It's for display purpose only 🙂
    And furthermore, there are no syntax errors in HTML. Syntax errors in HTML will be displayed as plain text 🙂

    HTML is not a "language" as it does not execute at the machine level as hexadecimal instructions on the processor. HTML merely defines the structure to a browser as how the document should be displayed.
    You could compare HTML to Postscript which tells the printer as how to print a particular document….. with a heading, paragraphs, font size, bold words etc.

  34. How does HTML beat C?
    Print("Under Construction %s", "404");
    Output: Under Construction 404

    Under Construction 404
    Output: *Closes browser and goes to sleep

  35. HTML is NOT a programming language. It is a text formatting language. They are two very different things. It's not that HTML is so "simple." It is designed for a different purpose. If C were better, web pages would use C for web pages.

  36. The <P> tag isn’t picky and doesn’t nest. But <DIV> is and does. And they are important when you get to JavaScript and CSS and you want to operate on parents and children. You need a hierarchy for that.

  37. I dont see the sense of this comparison. HTML and C are completely different in use and structure.
    since C communicates directly with the processor it cannot tolerate mistakes.

Leave a Reply

Your email address will not be published.