🚀 Take the Ruby on Rails Community Survey and help shape the future of Rails!
Article  |  Development

Haml - A Change of Heart

Reading time: Less than a minute

It was a couple of years ago when I was introduced to Haml. I believe my first time working with it was on an inherited project. The markup was very unfamiliar and a bit of a pain. Why would anyone want to abstract out HTML when you could just write it normally? It initially seemed like a needless, intermediary step.

I did recognize some of it's benefits. For example, it is nice to not have to worry about closing tags and the amount of typing it could save was pretty obvious. However, the indentation and other quirks seemed like a little too much to put up with.

So I went about my day, turning my nose up at the mention of Haml. Too cool for school, right?

Wrong. As with everything involving coding, it takes a day-to-day project to really give you a taste of a new language. As I started working on an existing project with a new team, I found myself working with Haml everyday for a few weeks. Gradually, I came to enjoy the shorthand as a way to markup HTML pages.

There were still little things that would trip me up or seem like a long way around to get to a simple solution. For example, if you want to end a sentence with a link and not have a space before your period, you have to do something like:

This sentence ends with a link which is
%b just
before a period
= succeed "." do
    %a{:href => "#", :name => "This is a Link", :"data-name" => "dataName"} the link

Also, as you can see in this example, adding things like data-attributes or names for tags need to be done in curly braces. These are just a few of the things you have to get used to when you are knee-deep in writing your Haml code.

Even though some of the syntax can be a bit of a stumbling block on your Haml journey, I found the other conveniences of the language far outweigh the perceived drawbacks. I am hoping that more of the projects that we work on, in the future, will be written in Haml. I think I will need to be a Haml evangelist to the other developers on our team.

My take is, 'If I can come around to loving Haml, anyone can.'

Robby still isn't convinced, though.

Have a project that needs help?