Thoughts on HAML
Feb 10, 2010 07:54

Over the last year or so I've been doing all of my new Rails development in HAML rather than in RHTML.

I've spent a lot of my professional life wrestling with 'helpful' frameworks that are supposed to make building web pages easier, but end up making the process more difficult (Lotus Domino, Websphere Application Developer, and Struts Taglibs, I'm looking at you!). These other frameworks were designed to help people who don't really know HTML or CSS, so they have lots of 'helpful' features to keep you from having to worry about what's happening underneath - features that end up getting in the way when you try to do anything new or different from their assumptions.

HAML makes a different assumption: you already know how to write HTML and as a matter of fact you don't want to be abstracted from implementation details - but you would like to work with something that's cleaner and more structured.

(Note that everything I'm saying here also applies to HAML's CSS cousin, SASS - but I'm just going to talk about HAML here to keep things focused).

Going from HTML to HAML is like going from Java to Ruby: there's so much less code to worry about and everything is so much cleaner. The logic and structure of the page is more obvious and it's easier to figure out what's going on. When the trees are smaller, it's easier to see the forest.

A good framework will make doing things the right way an aesthetic decision. I've found this in Ruby as well: because most of the code is terse and elegant, the awkward parts stick out more, and call out more to be fixed.

In fact, what I like most about HAML is the way that it makes bad habits ugly.

You're more likely to care about a piece of dirt in a beautiful clean room than in a filthy basement. Likewise, something awkward in HAML sticks out a lot more than it would in, say, PHP. If your desk or your kitchen or your code or your web page is already messy, an extra bit of mess isn't a big deal. If the context is already clean and elegant, there's much more incentive to keep things that way.

In the rush of deadline-based development, I often find myself taking messy short-cuts: one-off custom CSS attributes, big chunks of JavaScript mixed in with the page content, too much passthrough Ruby, or even using tables for certain kinds of layout. These hacks disappear into the muddle of regular HTML - but they stick out in a HAML page like a coffee stain on a white kitchen counter.

It's not a surprise that HAML comes from the world of Ruby and Rails, with its history of opinionated design assumptions and focus on powerful elegance and simplicity. Try it if you haven't yet - it'll bring aesthetics and clarity back to your HTML, and help you keep your good habits.

Next:
We're all LUsers
Feb 12, 2010 12:25
Other Blog Posts
Finding Burgers Fast: My DIY Halifax Burger Week Site "This is Nowhere" at PodCamp Halifax 2018 The Diary Diaries: Fixing Remembary's Facebook Connection Special Leap Day Edition of "Some Weird Things About Time" What's Up With Remembary Can't get pg_dump To Work Now That Heroku Has Upgraded Postgresql to 9.4? The Best Thing I Ever Did To Promote My App If You Build It, They WON'T Come #deployaday, My Big Hairy Plan for 2015 Extracting Plain Text from an NSAttributedString My Year of "Hits" Part 2: Remembary Rolling My Year of "Hits" Part 1: Remembary Rises (and Stumbles) Handy Little Test Method to Check for Translations in Rails Apps My Suddenly Slow-Waking MacBook Air Indie App PR: Keeping Control of Your Tone A Quick Note on 'clone' in Rails 3.2 My eBook Apps 2: iOS, JavaScript, and Ruby My eBook Apps 1: Introduction Quick Tip: No Sound on Mountain Lion My Upcoming Talk at PodcampHFX 2012: My Year of "Hits" starshipsstarthere.ca: Building at the Speed of Funny Screencast Tips Remembary's Cool New Picture Support Indie App PR 2: Keeping On Top Of User Feedback Indie App PR 1: How to Handle an App Disaster Giles Bowkett Diary Project 2 Remembary Video Congratulations! Welcome to Your Nightmare! How My iPad App Remembary Took Off Why You Should Have an App in the App Store (Even If You Probably Won't Make Any Money) PodCampHFX Remembary Presentation - Part 3 How I Used MailChimp Autoresponders to Promote Remembary PodCampHFX Remembary Presentation Part 2 PodCampHFX Remembary Presentation Part 1 Why AdWords Ads Don't Work for iPad Apps Remembary is Sponsoring PodcampHFX Why Can't I Resize my Views in Interface Builder? Momento and Remembary Concerning Remembary iPad-Friendly eBooks of Gracian's Art of Worldly Wisdom Project Report: PTOS2 A Quick Note on Encryption We're all LUsers Thoughts on HAML Friday Afternoon Hack - Getting Beyond the Basics Halifax Friday Hack and Back to Basics Quote from Wil Shipley FutureRuby Make Web Not War Busy Week I: Toronto Ruby Job Fair Employment.nil - the Toronto Ruby Job Fair Code Count: Ruby on Rails vs. C#/ASP.NET A Brief Note on Twitter The Hub Halifax and Mobile Tech for Social Change Deep Thoughts on Microsoft From The Accordion Guy The Two Kinds of Defensive Programming Presentation - Fixing Careerious: From C#/.NET to Ruby on Rails Enterprise! Presenting at Ruby on Rails Project Night - May 7th New Name and New Look for Careerious/Clearfit FutureRuby and More From Unspace Health Tips for Programmers This tables meme won't die Careerious - Ruby and Rails vs. C#/.NET Yeah I Use Tables For Layout, So Sue Me The Different Kinds of Done Giles Bowkett's RubyFringe presentation OfficeTime: Great Time-Tracking App for OS X Back With A New Look Non-DRY Feed torontorb Keeping Your Sanity With The Command Design Pattern shindigital Is All Grown Up! (according to the spambots) Startup Stars? I'm so bored! The Magic Words for RMagick Jennifer from Operations You see? Naming is HARD Business Software as Process Documentation Deployment note: 'execve failed' Steve Jobs on Market Research Why Canada Is Better for Entrepreneurs "Program first and blog second" Toronto Tech Collage The MacBook Air Is A Roadster RubyFringe! Quote of the Week: Steve Yegge Starting Up: Cards Great design tool: browsershots.org Starting Up: The Logo Quotes Of The Day: Hedge Fund Interview TSOT Ruby / Rails Presentation Night - Part 1 Moneyworks: Accounting Software for Canadians on OS X Starting Up: The Name Nice logo, but why is your site so bland? Welcome to shindigital.com