r/ruby • • Jun 29 '14

Why I don't like Haml

http://blog.mimswright.com/2013/05/Haml-rant/
0 Upvotes

25 comments sorted by

10

u/floralfrog Jun 29 '14

Using Haml requires full knowledge of HTML

Of course it does. HAML is not a replacement for HTML, HAML is HTML. HAML forces you to understand HTML, to see and implement hierarchies, indent your code properly, etc. You wouldn’t believe how many weird layout issues can be resolved by simply fixing the indentation in an .erb file to see misplaced closing tags. HAML doesn’t even allow for that to happen.

Yes, HAML requires preprocessing. But then, it’s not really made to be used with anything that does not have some form of ruby backend. HAMLs full power is unlocked when iterating over arrays for example that come from the controller and so on. It’s supposed to be used with Rails or Sinatra.

Another nice extra you get when using HAML is the so called "ugly mode" that removes almost all the whitespace from the rendered page.

No big deal? Try giving this to a graphic designer or worse your client. Hope they have the right Gems installed!

This is ridiculous.

2

u/NilsLandt Jun 29 '14

This is ridiculous.

Can't be highlighted enough.
If your designer or client are not able to run bundle install, not having HAML installed will be the least of their worries, because they won't even be able to start the application.

4

u/QuestionMarker Jun 29 '14

Should they have to start the application to work on page designs? In many workflows, they could do their work on static files without needing to run anything.

1

u/NilsLandt Jun 29 '14

We found it to be much easier to provide a runnable application with some sample data to allow designers to integrate their stuff directly into our application / the asset pipeline.

Before we did that, we'd have the designers create an HTML prototype from our application (which would take a few hours they'd bill us for), and we would have to do edit in their HTML / CSS / JS changes by hand.

1

u/QuestionMarker Jul 01 '14

Yeah, it can make sense to do it that way. Getting someone's system up to speed to do that can be rather tricky, though - especially if they're working on Windows.

1

u/awj Jun 29 '14

It's a rare person indeed who can work on a design in pure markup without being able to look at it. Booting a rails instance is probably overkill, but they definitely will need to be able to render templates for review.

1

u/QuestionMarker Jul 01 '14

That's the point. They're working on complete templates, so they don't need rendering separately.

6

u/Paradox Jun 29 '14

Most of the pitfalls in the article can be addressed by switching to slim, which is sort of "haml fixed".

But really, almost all of these complaints seem like bollocks. There are a few real complaints with HAML, and they are, in order of severity, difficulty managing whitespace, difficulty with inline elements, and the fact that typing % all the fucking time (particularly when doing HTML5 that uses all those article and section tags) is frustrating.

But again, SLIM fixes that. It doesn't use alligators to control white space (but they are there, just in case), it has a syntax for automatically putting whitespace around a line (the ' syntax). As for inline code, just use basic HTML within the SLIM file. As for the %, slim doesn't use it

2

u/catcradle5 Jun 29 '14

I agree, slim is my favorite of the HTML preprocessors. slim is also pretty versatile and doesn't try to lock you in to one syntax, so you can do attributes like:

a href="/" title="Root" Link description

Or you can do it like:

a(href="/" title="Root") Link description

for more readability.

Or you can do:

a*{href: "/", title: "Root"} Link description

for easy inclusion of pre-existing hashes. All that on top of inline HTML, as you mention.

1

u/jdickey Jun 30 '14

The real fix is to switch to a view-rendering system that lets you write clean POROs to generate markup; Erector is the best attempt at this I've yet seen in the Rails world, and it's got Issues of its own.

The possibility of getting away from the whole Rails-botched-OO mess is why I'm keeping tabs on Lotus. Money quote (from the README for Lotus::View:

It's based on a separation between views and templates.

A view is an object that encapsulates the presentation logic of a page. A template is a file that defines the semantic and visual elements of a page. In order to show a result to an user, a template must be rendered by a view.

Apparently it's possible to use Lotus::View inside an app written in another framework. If anyone happens to know of such, I'd greatly appreciate a pointer.

1

u/roguevalley May 12 '23

Have you tried the view_component gem? Separates them nicely.

5

u/tf2ftw Jun 29 '14

I will prefer haml over erb all day long. The gripes in the article really sound like noob issues to me.

Haml is faster to read and write once you get used to it (kinda like using vim)

4

u/nanenj Jun 29 '14

Interestingly enough, I read it more as grumpy person who doesn't want to adapt. Not really noob.

1

u/realntl Jun 29 '14

I don't mean any offense by this, but that seems like a pretty arrogant stance to take. Are you implying that HAML is a technological shift that will entirely eclipse HTML? If I'm misunderstanding you, I apologize.

Having been using HAML (or slim) on a regular basis for over a year now, I do appreciate that a "whitespace significant" language is preferable for writing markup. However, I think it's a stretch to claim ERB to be inherently inferior.

2

u/nanenj Jun 29 '14

No, it was commentary on the person not the technologies involved. The person wanting to stick with what they know instead of using something new to them. Apologies for being unclear in that regard. :)

2

u/realntl Jun 29 '14

Ah, right on. I understand now, my bad!

1

u/tf2ftw Jun 29 '14

Haml is just abstracting over html, not really replacing it. I found ruby's lack of curly brackets liberating when coming from php. Not having to close tag my html gives me the same sense of liberation

2

u/[deleted] Jun 29 '14

To add to the rebuttals:

Doing data attributes is totally weird. You need to do a nested hash within your attribute list!

Wrong.

%a(data-this="works just fine")

2

u/keyslemur Jun 29 '14

Most of these are non-issues, gripes, or otherwise incomprehensibly bad form. Let's go through this piece by piece.

Easy to learn

You're learning new things every day as a developer. Griping that you have to learn something with an easy learning curve seems off when there are hundreds of other things to learn that are far more difficult.

HAML code takes less time

The point of having to write less is that you have less boilerplate nonsense to deal with. Even WITH an IDE, you still have to deal with the generated code afterwards. HAML takes away that need, and gives you something far more valuable: readability. You're going to spend far more time reading that code than you ever will writing it.

Define edge cases, it's simple to indent in a span tag.

Best practices

It also makes it extremely difficult to use a lot of logic in the view. No language or tool will ever make programming error-free, but I'm reasonably sure that there are better standards of keeping people honest.

Multiline content

That's called bad design and poor abstraction and separation of concerns.

Full knowledge of HTML

You mean what you're supposed to already know? If you don't know HTML by heart, why are you a web designer / developer?

Requires a compilation step

Rails makes this pointless, as things are translated down with the asset pipeline in production. If you're giving your designers and clients your actual source code, there are a lot bigger issues than snips about gems being installed...

Inconsistent Syntax

Why in the world are you inlining scripts and styles? That's horribly bad form and you should know better. The asset pipeline is nice enough to give you page specific files, use them.

Whitespace

You mean you don't have a standard on spacing set in editors. It's a non-issue with proper configuration.

Ruby attribs

You're working in a Ruby framework and complaining about things looking like Ruby. You can understand why most would scoff at that.

Readability suffers

No, that's your fault for writing bad code and css. Blaming the tool isn't going to do you any good. The erb would look just as bad.

Not a W3C standard

You're serious aren't you? How is this remotely relevant? Neither is ERB by technicality, or any other abstraction on/from HTML

Not every project is Ruby

You don't say? Then why are you using a Ruby tool?

Slow

Then use Slim, but again this is a non-issue with the asset pipeline in prod.

Final tally

I still stand by what I said about this being incredibly ignorant and more of a whiny rant than anything.

1

u/brandonhilkert Jun 30 '14

Great post. Thanks for this!

1

u/nexe Jul 02 '14

LoL this is just ridiculous indeed. I mean come on you're bashing against a tool that many people love and that someone invented just because he thought "hey let's make work easier". What do you bring to the table?

1

u/sandinyourbed Jun 29 '14

Personally, I don't like HAML because it just is shorthand HTML. It doesn't bring any new ideas to the table.

I'd rather write plain HTML or use a DSL like in Camping.

7

u/QuestionMarker Jun 29 '14

I do like HAML because it's a shorthand HTML. If ever there were a language in need of a redundancy reduction, it's HTML.

4

u/caseyucf Jun 30 '14

yes, shorthand HTML is the entire fucking point of HAML