← Back to Upcase

Slim vs. Haml


(Justin Gordon) #1

Any opinions on Slim vs. Haml for rails? I just picked up a project that’s using Slim.

I haven’t done enough with it to comment one way or another. The arguments for Slim are:

  1. Performance. One very recent article states that Slim ugly indeed is much faster than haml, while slightly slower than erb.
  2. More clarity than Haml (subjective).

Certainly, Haml is more mainstream.


(Geoff Harcourt) #2

TL;DR: Minor argument in favor of Haml, followed by rant about intellectually dishonest benchmarking use.

I think adoption rate is a pretty powerful argument in favor of Haml, provided you think your project will ever have collaborators beyond yourself. I have found more design help that has some Haml knowledge than Slim thus far (admittedly in a small sample size).

The Rant on Benchmarking

I wouldn’t worry too much about performance when making this choice. In the benchmark shown there, the percent difference looks large, but the actual amount of time is tiny (a fifth of a second deficit over 1000 template rendering iterations, or if my math is correct, .0002 seconds per template rendering). I have a huge issue with benchmarking like this, because it strikes me as intellectually dishonest to point at these numbers and pretend they actually mean something (again, if my math is way off here, open to being un-convinced). The author actually increased the sample in the second test run from 1,000 iterations to 100,000 iterations, and the performance hit declined on a per template-load basis.

Even if Slim were faster in any meaningful way, if template rendering speed is one of your major performance battles (meaning you’ve defeated asset load time, database queries, etc.) you’ve already won the war.


(Justin Gordon) #3

I’d agree on the pluses of standardization. It’s been a slight productivity drawback for me to have to switch back and forth with the haml and slim syntax.


(Geoff Harcourt) #4

@Justin_Gordon that’s definitely an argument in favor of doubling down on what you know and are using. I wouldn’t suggest converting templates in an application from one language to another. If the rest of the app is using Slim, keep using Slim. My advice should only apply to new apps, or perhaps to new templates in an existing app if a whole team wants to make a transition.


(Justin Gordon) #5

@geoffharcourt Doubling down on Haml is a paradox when my latest client’s codebase was started using Slim. :smile:


(Nicholas Ng) #6

Sorry, maybe out of the topic, how about html.erb Vs (SLIM & HAML). Slim and Haml seems need to process the syntax while html will not process anything. Besides, if using html, any new member of the project will get used to it since html is kind of basic language, whereas slim&haml, there will be a learning curve for designer and new comer. Thoughts?


(Luís Ferreira) #7

I find both slim and haml pretty much straight forward in most use cases. That being said we’ve been using Slim in all projects for over a year simply because we find it more readable that haml (if not using other templating engines, such as handlebars or mustache).

Also, the documentation is pretty good.


(Justin Gordon) #8

After using slim for the past few months, I’m liking it more than HAML. However, both get the job done nicely. If doing a new app, I’d probably lean toward slim.