Where HTML beats C - Computerphile

The Complexity of Navigating Sequences and Nested Blocks: A Debate between HTML and Programming Languages

When it comes to creating content, whether online or offline, one fundamental aspect is understanding how to structure information in a way that makes sense. In recent years, two approaches have emerged as contenders for this task: HTML and programming languages like C, Java, and basic. While both methods have their strengths and weaknesses, they approach the problem of organizing content from different angles.

One of the key differences between these two approaches is how they handle sequences and nested blocks. HTML has a simplistic approach to structuring content, relying on sequential nesting of elements to convey meaning. This can lead to a straightforward, linear presentation, but also means that users must be mindful of their markup to avoid mistakes or unwanted behavior. In contrast, programming languages like C, Java, and basic allow for the creation of more complex structures, such as nested loops and blocks, which can result in deeper hierarchies of content.

For instance, consider a simple program written in pseudo-code: `print F hello Sean` followed by another loop that goes around 10 times. Closing off the block with a semicolon would produce a desired output of "hello Sean" printed 10 times, followed by goodbye Dave. However, when nested blocks are introduced, as in `loop around 10 times on the following print F hello Sean 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 another loop block inside It Goodbye Dave`, things become more complicated.

The programmer would need to carefully balance opening and closing brackets, lest they create an ambiguous situation. This is where the limitations of HTML come into play. While it can handle nested blocks to some extent, its simplicity means that it relies on careful user input to maintain coherence. Unlike programming languages, which can explicitly define sequences and nesting rules, HTML's approach is more intuitive and less error-prone.

However, this flexibility also means that HTML must impose a certain structure on the content being presented, in order to make sense of it. This can sometimes result in an "imposed model" where the actual content deviates from what the user intended, leading to frustration and potential mistakes. For example, if a user writes `print F hello Sean` without closing off the block with a semicolon, they might inadvertently create an output that is not entirely what they desired.

The issue of nesting blocks in HTML arises when considering how to handle ambiguous or unclear situations. If both possibilities are possible, it can be challenging for the browser to determine which one to choose, making it difficult to "repair" the content correctly. This highlights a fundamental limitation of HTML's approach: it is not designed to solve complex problems but rather to impose a structure on the content being presented.

In contrast, programming languages like C and Java are capable of solving these complex problems explicitly, through careful design and implementation. However, this comes at the cost of increased complexity, as users must be more mindful of their code and its potential consequences. The trade-off is one that reflects the fundamental differences between HTML's intuitive simplicity and the more deliberate approach of programming languages.

Another advantage that programming languages have over HTML is their ability to handle deeply nested hierarchical structures. While HTML can nest blocks to some extent, it is not well-suited for creating complex, multi-level structures. In contrast, programming languages like C and Java allow for the creation of such structures through careful design and implementation.

The impact of this difference was recently demonstrated when an image processing application applied one of these approaches to achieve impressive results. This highlights the potential power of HTML's approach, even in contexts where more complex problems are being solved.

Despite these limitations and advantages, both approaches have their strengths and weaknesses. The question of which one is "better" ultimately depends on the specific context and requirements of a project. However, by understanding how sequences and nested blocks work in each approach, users can make informed decisions about when to use HTML's intuitive simplicity versus the more deliberate design of programming languages like C and Java.

"WEBVTTKind: captionsLanguage: enbut 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 you troubles you get into if you are promiscuous right and you are promiscuous why because part of what HTML does is you have to visit other people's websites 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 p and I'm going to just put a piece of text in here which says hello Shan even though I absolutely don't have to do it nevertheless I'm going to do it I'm going to close off the paragraph and then I'm going to open up another one straight away afterwards goodbye Dave once again we close off with a SL P 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 parah within a parah you can see the difference I've opened up a paragraph I've said hello Shan 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 fitting inside the outer one and then I dutifully close them both off you might think oh I know what it'll do I might get hello sha 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 the nesting or anything so if we develop these a little bit further now we could say okay do the P hello Shan do another P goodbye Dave so you're admitting the closing bit is that right omitting the closing of the paragraphs is that acceptable to HTML yes it is nothing's going to fault you for missing out end of p and that if youve type that in will look the same as that it wants to put the end tags in and obviously in some 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 p 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 end PS in and sometimes didn't and the answer is 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 can 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 combination you could have a sequence of nests or a nest of sequences but if you once start saying they can both coexist nesting uh 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 they if both possibilities are possible then you can't have Smart Behavior because it cannot know how to repair it correctly and what HTML is doing is it's not solving the in 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 you know and all that and that's why it can get away with murder now for those of you who've ever 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 want print F hello Sean and C programmers will know that if you want a new line at the end of that which you do you better put a back sln at the end we're going around 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 10 times then I do another loop that goes around 10 times goodbye Dave new line close quotes semicolon let's hope this really would compile you can all see what's going to happen when you execute this I'm going to get hello 10 times then goodbye Dave goodbye Dave goodbye Dave goodbye Dave 10 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 print F hello Sean 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 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're 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 Sha but every time it does a Hello sha it then goes into a nested in a loop that does 10 goodbye daes so for every one hello sha I print out I'm now getting 10 goodbye Daves net result I will end up with a 100 goodbye Daves interleaved between 10 hello shaes whereas in the earlier case I had 20 printouts I had 10 hello shaes followed by 10 goodbye days lots of students have said to me over the years the C compal is so clever why can't it put my programs right for me and the answer is if you emit 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 unambiguous ously put back the Clos curly braces if users emit 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 see 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 someone came along applied one of these to image net and got incredible results and so on and so forth and now there's this big push and everyone's trying to get even better results and even better resultsbut 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 you troubles you get into if you are promiscuous right and you are promiscuous why because part of what HTML does is you have to visit other people's websites 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 p and I'm going to just put a piece of text in here which says hello Shan even though I absolutely don't have to do it nevertheless I'm going to do it I'm going to close off the paragraph and then I'm going to open up another one straight away afterwards goodbye Dave once again we close off with a SL P 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 parah within a parah you can see the difference I've opened up a paragraph I've said hello Shan 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 fitting inside the outer one and then I dutifully close them both off you might think oh I know what it'll do I might get hello sha 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 the nesting or anything so if we develop these a little bit further now we could say okay do the P hello Shan do another P goodbye Dave so you're admitting the closing bit is that right omitting the closing of the paragraphs is that acceptable to HTML yes it is nothing's going to fault you for missing out end of p and that if youve type that in will look the same as that it wants to put the end tags in and obviously in some 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 p 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 end PS in and sometimes didn't and the answer is 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 can 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 combination you could have a sequence of nests or a nest of sequences but if you once start saying they can both coexist nesting uh 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 they if both possibilities are possible then you can't have Smart Behavior because it cannot know how to repair it correctly and what HTML is doing is it's not solving the in 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 you know and all that and that's why it can get away with murder now for those of you who've ever 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 want print F hello Sean and C programmers will know that if you want a new line at the end of that which you do you better put a back sln at the end we're going around 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 10 times then I do another loop that goes around 10 times goodbye Dave new line close quotes semicolon let's hope this really would compile you can all see what's going to happen when you execute this I'm going to get hello 10 times then goodbye Dave goodbye Dave goodbye Dave goodbye Dave 10 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 print F hello Sean 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 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're 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 Sha but every time it does a Hello sha it then goes into a nested in a loop that does 10 goodbye daes so for every one hello sha I print out I'm now getting 10 goodbye Daves net result I will end up with a 100 goodbye Daves interleaved between 10 hello shaes whereas in the earlier case I had 20 printouts I had 10 hello shaes followed by 10 goodbye days lots of students have said to me over the years the C compal is so clever why can't it put my programs right for me and the answer is if you emit 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 unambiguous ously put back the Clos curly braces if users emit 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 see 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 someone came along applied one of these to image net and got incredible results and so on and so forth and now there's this big push and everyone's trying to get even better results and even better results\n"