Hacker News new | ask | show | jobs
by yoavm 1068 days ago
I love Haml / Pug / Slim. I think it's very clear what problem it solves: you don't need to worry about closing tags, and doing it in the right order, because the tree is visually in front of you. It also means less code (because of no closing tags), which means it's easier to read.

It's like HTML but less verbose, less errors prone (<p>foo<b>bar</p></b> is impossible to write), and basically the formatter is part of the language. What is there not to like?

2 comments

Not having to worry about closing tags can be solved in numerous other ways without having to invent a new language. And strictly speaking, Haml doesn't actually remove closing tags - it replaces them with whitespace defined structure. This introduces new classes of problems. Like having to deal with when it is unclear when the whitespace is part of the structure versus when it is part of the content. There is a reason why the Haml reference has a section on this.

Then there's all the other syntax that needs to be crammed in to make the language do what you want. HTML doesn't have lots of special characters strewn about the place that have meaning, but Haml does. You now have to understand HTML, Haml and how Haml is turned into HTML. That's a lot more complexity than sticking close to HTML.

It seems like a lot of unnecessary work to use Haml (and impose it on other people through code) if your reasons for using Haml are purely superficial.

Why invent a new language so you don't have to close tags? Do I miss something?
> so you don't have to close tags
sure, I guess lighting the house with fire also works!
In my experience, adding a layer between you and what you are doing adds a potential layer to every bug, and a layer to what new developers need to learn. That needs a lot of justification.
One of these major “no closing tags” templating languages had been chosen for a Rails project I once onboarded to. I wanna say it was Slim, but it may have been another.

It was dog slow and it had some really stupid api you had to use if you needed to handle nesting that you couldn’t determine until runtime (on account of the no closing tags—use case: rendering a tree of data in a streaming-records sort of situation, not exactly a super-rare need).

There was a faster implementation, several times faster… but it achieved that in no small part by ditching the bits of the api that allowed you to manipulate nesting, so I couldn’t use it.

That project made me hate crap like this. HTML isn’t scary, hard, or even (in a halfway modern editor) slow to write, FFS. I’ll never ever pick this sort of templating language when it’s my choice.

True, but almost no one is writing HTML anymore. So if I'm anyway post-processing my tsx / jsx / vue / whatever files, I might was well use a language that's great.

As for adding a layer to what devs needs to learn - that's why I don't generally use this at work. In those situations you often need to pick the most common tools and not the best tools.

> almost no one is writing HTML anymore

JSX?

That’s right, JSX is also not HTML.