Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm interested as to the anecdotal benefits of using a templating engine like jade or haml. I much prefer the longhand way of embedding code into handcrafted HTML, but then I date back to the early PHP and ASP days and use Django heavily at the moment. Can't quite wrap my head around this mix of generated tags and logic.


With HAML, the big wins for me are:

1) Not making nesting mistakes

2) Less escaping junk(<? ?> or <% %> or whatever)

3) Generally fewer characters to wade through

4) Not having to think about the fact that HTML files are strings... thinking in terms of DOM structure instead.

The things it doesn't handle as well:

1) Micromanaging whitespace between tags (I know, there are solutions, but they're still awkward)

But in truth, HAML kind of reminds me of Rails in that it doesn't actually DO anything you can't do for yourself... but it does change how you think about/structure your code. I'm pretty sure that if I were to go back to writing raw HTML, I would structure/indent it like a HAML document... the same way my non-Rails apps end up looking a lot like Rails now that I've seen how that works.


After doing it the longhand way for over 10 years, I will never go back to that after using Haml. It just feels like the right solution to the problem of dealing with lots of nested markup. It might not be obvious what a benefit it is until you try it. I actually use my own custom-rolled flavor of Haml that is less Ruby-like, and I think it maps a bit better to the stylesheet and javascript.

On the topic of javascript templates, I tried Jaml for a while because I really wanted to have templates that could be cached on the client-side, but the function-based approach was really cumbersome. I ended up creating a server-side pre-processor that converts Haml to vanilla javascript functions that just build the output using string concatenation. These are called at run-time by underscore's template function. Overall, I'm totally happy with it so far.


- faster to write

- less thinking

- easier to modify and understand

I've been writing longhand for 10 years, and it was a no brainer. Just download it and try it on a project for a day. If you are not sold, you can always go back (since it just generates regular html).

I also highly recommend sass over css. The benefits of sass over css is much greater than the benefits of haml over html.


I agree about sass.

Haml is Much easier to diff/ merge




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: