HAML, SASS, and ERB are all tools. From what I’ve seen, they are all very good quality and they all have their shortcomings. You can write “brief elegant code” and “horrible spaghetti code that should never see the light of day” in them all.
But I choose ERB for all of my projects and anything I open source:
- The #1 reason I use ERB is because 99% of the development I do is with existing code base in ERB. Sure, ERB and HAML can be mixed but that’s not a road I want to go down. I’ve already tried to mix Test::Unit and RSpec in a few projects and it’s not maintainable at all (Test::Unit in the core code, RSpec in the plugins).
- Even in a brand new project, I will not use HAML if that project is going to be open source. Since ERB comes with Ruby and Rails, there is no additional requirement to getting it installed and setup. HAML and SASS both need additional gems installed in order to work. For Rails developers this might be easy but how “easy” would this be to explain to a non Rails developer who wants to use your software? Could you explain how to install HAML and SASS to your great Aunt Tillie?
- I’ve personally found that SASS doesn’t play well with several deployment environments. Having to compile your CSS when deploying is yet another barrier to getting your software setup. I was also surprised at how many Rails applications are deployed to a environment with a read only public directory. This is not just on Heroku, it’s also in many enterprise IT shops.
That said, HAML and SASS both have a lot of good ideas. I’ve only worked on trivial HAML applications but the views does look cleaner than ERB. I’d think that in more complex applications, HAML could get just as messy as ERB though. I also really like how SASS lets you add some dynamic bits to your CSS. I haven’t found a really elegant solution to this yet using ERB, other than dumping inline CSS for the dynamic bits.