Page 1 of 2
HTML5 is all the rage and yet it could be so much better. There is one single change that could be made that would make it much more useful and the change wouldn't break any existing web pages or applications.
So what is this magic ingredient?
Simply stop insisting that HTML is a markup language and allow it to evolve into an object-instantiation language.
That was easy - now let's look at what it all means and why it is such a good idea.
HTML started out life having nothing at all to do with programming. It was intended as a markup language for hypertext documents, and it serves this role increasingly well. HTML5 takes this purity to the extreme and proclaims HTML as a "semantic markup language" leaving every aspect of what the page looks like up to CSS. This isn't a bad idea and the whole separation of concerns idea is an important and useful one.
We really shouldn't have any problem with semantic markup.
Enter the DOM
Basically the idea was simple - each HTML element corresponds to an object in an object tree that mirrors the nested structure of the document.
Simple and effective but for a small omission.
But wait a minute - why not couple to the two together?
HTML as declarative UI language?
After all, every language needs some sort of UI technology and these days that technology is usually in the form of a markup language of one form or another. That is, a declarative UI creation language is a good and modern contrivance and every language either has one or could be made better by acquiring one.
HTML for object instantiation?
Attributes of each element also become properties of the instantiated object. So for example:
adds a class property to the Button and sets it equal to "MyButtons". Some attributes could, and should, be mapped to more general programming constructs. For example, the id attribute could be mapped to the instance name. So instead of having to go through the usual process of looking up a DOM element by id you could just write either:
or if you want to avoid polluting the global name space:
You could leave all of the DOM get functions and all of the manipulation functions they would still occasionally be needed and they would provide backward compatibility.
Now we come to the interesting part. As an object instantiation language HTML would now be extensible. If you included a tag on a page that wasn't part of the current standard: