What is HAML?
HAML is a markup language. It’s specifically designed to replace the HTML + ERB combination typically used in Ruby applications to render web pages.
Why I like HAML
HAML is nice for several reasons, all revolving around how its files are structured.
First, it’s indentation driven. I have run into a few issues with indentation, but for the most part, it’s pretty clear which parts of the page are within other parts of the page. I’ve never been a fan of whitespace delimited code, but in this case, it’s kind of nice.
Second, adding a class or id to an element on your page is as simple as #id or .class rather than class=”class” or id=”id”. It’s not just about saving typing. I actually find it easier to read.
Third, HAML includes SASS. SASS, or syntactically awesome stylesheets, give you a lot of features like storing your colors, sizes, and other common settings in variables, nesting styles, and inheritance. This saves you a TON of copying and pasting in your stylesheets. You can say $chadfowlerpink instead of #993366. (Click here if you’re wondering about Chad Fowler pink.)
Finally, you don’t have to declare your div tags. This is particularly useful because most layout these days is done using div tags and css attached to your classes and ids. So, instead of <div class=”…”> all over the place, you see .class1.class2.class3#id.
Sounds Great! Why Wouldn’t I Use It?
HAML use really boils down to the people involved. I’ve worked with several designers who work very well in HTML and CSS. I’ve also worked with several developer who have never programmed with HAML. These are the two types of people you need to consider when choosing HAML. Collaborators and maintainers.
Is it worth forcing collaborators like designers to undergo the learning curve to learn to use HAML? HAML comes with an HTML converter. Is it worth the extra step if they’re not going to learn HAML? Weighing the collaborators’ learning curve against the increase in productivity you’re likely to see as a developer is worth considering.
As for maintainers, keep in mind that you’re not likely to be the programmer building this project forever. Are you making it more difficult for your employer or client to find someone who can pick up their application and continue to work on it? Are you adding to the training required for new employees? (I don’t find this to be too much of a problem with new developers.)
HAML doesn’t have a steep learning curve, so in most cases, using it is worth it. But these are questions to keep in mind.
Where do I get HAML?
You can find out more about HAML at http://haml-lang.com/. To install it, just
gem install haml