Hacker News new | ask | show | jobs
by Udo 4488 days ago
I know the use of object-to-HTML-mappers is only going to grow from here on out, but I really don't see the appeal in most cases where pure HTML would have been a perfectly readable and lightweight choice. We're becoming so scared of angle brackets that we seek refuge behind object-like constructs that are nothing but yet another impoverished and leaky abstraction layer above an already abstract markup language.

Look at that nightmare of a rendering code and tell me you'll still want to touch that when the time comes to go back and modify it in a few months.

I had the displeasure of working with Jade on a recent project. Not only was it more difficult for humans to parse than the HTML it produced, it was also slow to execute and generally cumbersome to modify. The main purpose of its existence might just be so programmers can lie to themselves about separating code from templates, and making those templates look really sophisticated at the expense of productivity.

The battle cry "nobody should write literal HTML anymore" is not a good enough reason to do this - in fact it's not even a reason at all to begin with.

The example code in the article, well, I'm sorry to say that it's unreadable, convoluted, and huge for what it actually does. Both versions are terrible in their own way, only the JavaScript one is also deliberately sabotaged in order to really stand out as an abomination.

That being said, if there are people looking at this going "my, that does look mighty pleasant" - all the more power to you. A huge part of programming is finding technologies that map well to your brain. It just doesn't work for me at all (I needed to vent that just now, thanks for bearing with me) and I kind of hope I'm not alone.

6 comments

It's pretty indisputable that jade, haml, etc takes about 10% of characters to write vs plain html. There is nothing in html that can't be expressed in jade, and if you would prefer to use html you can put it in as plain text behind a | (I often do this for links in text). The lack of closing tags eliminates the most common cause of html mistakes completely.

If you don't like jade, I can respect that, and most of the time I use html for work because of factors that I can't control and it's no problem.

But you need to come to terms with the fact that your dislike of the language is caused entirely by your (I'm guessing) long experience with html, which has made you unwilling to gain proficiency in something new. Jade is objectively simpler than straight html.

It actually looks much more pleasant than HTML. The syntax is almost identical, except that HTML is much more verbose and difficult to read. This is a very different beast from Jade - Lisps translate to HTML very easily and transparently.
I'm not the world's foremost Lisp advocate, but you're absolutely right. It's even better than HTML in the sense that you don't have the "sometimes close the tag, sometimes not close the tag" inconsistency issue.
The difference is that a traditional approach requires you write code that updates your templates (the function `update` in his javascript example). The React version has no analogous logic. So you end up writing less code, and the code you do need to write is simpler.
"nobody should write literal HTML anymore" isn't really relevant. React actually goes out of it's way to enable HTML syntax with JSX.

the templating is subjective. i for instance prefer writing my template in the same language as it's logic.

> only the JavaScript one is also deliberately sabotaged in order to really stand out as an abomination.

I hope this is the case, otherwise someone somewhere thought this was the best JS code to solve the problem:

for (i = _i = _ref = this.length - 1; _ref <= 1 ? _i <= 1 : _i >= 1; i = _ref <= 1 ? ++_i : --_i) {

I would guess this is JS transpiled from CoffeeScript or something similar. That makes it an even less fair comparison, as ClojureScript would compile down to something just as wacky looking.
Weird. I've come back to our Jade templates months later, thankful I decided to use to Jade. My only beef with it at the time was the lack of documentation, but that seems to have improved since.