Thursday, July 15, 2010

The thing I hate about HTML

Is end tags. They are the source of HTML evil.

Consider this:

<div class="red">
<p>
Hello, World!
</p>
</div>

Now, ask yourself: do we really need the end tags to say what they are ending? I mean, what's the difference with this?

<div class="red">
<p>
Hello, World!
</>
</>

The problem with having named end tags and browsers that are kind to bad developers is that it lets you do something like this and get away with it. The browser magically says: "Oh, he must have meant to close that <p> tag so I'll do it for him.

<div class="red">
<p>
Hello, World!
</div>

HTML really ought to look like this:

(div class="red"
(p
(Hello, World!)
)
)

Given that the tags are meant to be balanced there's no reason to force the author to figure out which tags they want to balance and force them to write it down. It adds nothing. If they get the balancing wrong then they should be punished for it and clean up the page. Writing nice end tags is busy work that satisfies the mediocre. Without them we'd have nice, parseable pages.

But what do I know, I think LISP is cool.

PS Yes, I know there are some tags that don't need end tags (e.g. <img>). But that's just messed up. Also, <p/> would simply be (p) in my scheme.

PPS Since people were bitching about me using font and center tags I've changed them.

17 comments:

Peter said...

Haml may be the answer to your prayers.

Watts said...

http://haml-lang.com/
http://staticmatic.rubyforge.org/

Never type a closing tag again.

Steve said...

its less readable this way.....imagine having to figure out what closing tag is what when it looks lik
)))))))))))))))))))))))))))

Admin said...

Why are you using font tags still?

Bark Madly said...

in fact yesod uses haml like syntax to represent html
http://docs.yesodweb.com/

Josh said...

Here's an article that came to similar conclusions:

article

booch said...

You definitely need to look at HAML. It's basically your last example, except without the parentheses. You (and others) might not like the enforced whitespace at first, but just push through that, and you'll learn to love it. A lot of people started out hating the enforced whitespace, but love it now. I didn't like it at first in Python, but now I wish all languages used it. It solves the problem of indentation fooling you.

Phil said...

HTML5 seems to be a bit better:

http://dev.w3.org/html5/spec/Overview.html#optional-tags

Matthew said...

I can see it now... the great confusion that occurs when someone wants to actually use parentheses in a string and have it displayed.

(html
(head)
(body
(p (oh hello (or buenos dias!))
)
)
)

so then lets use something like lisp then

(html
(head)
(body
(p ("oh hello (or buenos dias!)")
)
)
)

okay good... but now what if you're doing quotes in the string... lets start escaping!

so now we have more complex escape sequences and what not

(html
(head)
(body
(p ("oh hello (or \"buenos dias\"!)")
)
)
)

okay, might be managable... but not lets start doing some php to generate content... that should be fun!

whereofwecannotspeak said...

You can do something very much like this in Racket (formerly PLT Scheme). See: Web Applications in Racket. I'm not sure how much of the PLT Web framework is needed just to do the rendering of lists to HTML, though.

WebDevHobo said...

For me, this boils down to the fact that you're lazy.

HTML is fine as it is.

Aaron Davies said...

for the correct definition of "HTML", <p></> is perfectly legal, since it's an available SGML syntax. it's not terribly common anymore, but i bet if you declare your page as html 3.2 or 2.0 it'll work.

bbot said...

I just C-c / and emacs closes the tags for me.

Francis Turner said...

I have to admit that when I'm creating html and templates I tend to do the cration in a perl script that starts

use CGI.pm qw/:standard/

Louis said...

This is what happens when we have physicists going around inventing computer languages that become global standards... everyone pays a price. That price is end-tags.

WTF? Did anyone check his work?

题叶 said...

I agree that Lisp could be fun with HTML, would you like to try my HTML: http://repo.cirru.org/html/

Cogwheel said...

<b>this <i>is</b> valid </i>html. No balancing here.