I Heart SASS, But HAML, I'm Just Not That In To You
intridea.com
intridea.com
In terms of learnability, it takes 15 minutes to learn 95% of the haml featureset. So you spend 15 minutes, then presto, less repetitive stress injuries from hitting the shift key all the time when creating view templates. AND it's much easier to read, and it forces correct indentation. That's just a whole lot of win.
Also, haml and sass are not mutually exclusive, nor are they a pair. They are 2 different tools that work with 2 different things.
Don't forget the people than need to clean up the typos
from the non-syntetic-sugar - aka "keep it native" - guys
HAML has some features which prevent from making typos when typing code? Interesting. Anyway, I am not sure what typos are you talking about. Syntax-highlighting + validation is good enough combination for me to avoid typos.
Honestly, never had that problem. and pay the salaries for work that takes 3 times longer
Why would it take three times longer? I do produce my HTML manually, but that does not mean I type every single character in the code by hand. Snippets, Zen-coding/Sparkup, autocomplete, etc.—all this allows to produce HTML fast, efficiently and avoid syntax errors.Most common problem with manually generated XML/HTML is broken tags (not closed correctly).
"Why would it take three times longer?"
The number 3 is just picked by me based on my own experience - I finish views way faster than the ones I've worked with, with best-pratice semantics. If you write valid semantic HTML as fast as me with no tool you are just very good, but you don't represent the majority.
This SASS thing, it seems interesting… I'm a Scheme programmer. I'd like something like it. After about forty-five minutes of hacking, I came up with this:
https://gist.github.com/956113
It lets you write code like this:
(make-css
'(("body.loading"
(font-size "12px")
(color "#fff")
(" ul#sidenav"
(" li"
(blah "blah"))))))
And generates output like this: body.loading { font-size: 12px; color: #fff; }
body.loading ul#sidenav li { blah: blah; }
I agree with the guy's point though: SASS is different from HAML in that it actually does something conceptually useful, viz. it introduces a scope-like concept to CSS.2. Syntactic sugar isn't just hand-waving; it has a reasonably-concrete definition. And it's generally considered acceptable if it delivers enough convenience (The concept of enough, you will find, is highly subjective.)
3. No one in this exchange has busted on the utility of SASS, so I don't understand why you'd deny anyone a SASS-like tool in a cage match nerd bake-off. For that matter, no one has busted on the practical utility of HAML in this exchange, just on the absence of new concepts i.e. powers of abstraction.
2. Reference me the official definition. Another point that didn't add anything to the discussion.
3. SASS been heavily hatred on in the past, Google it. Practical utility: Inofficially 80% of Rails/Sinatra developers use HAML - why? Because it makes people productive.
https://gist.github.com/957123
The example above can now be written thusly:
(make-css
'(("body.loading"
font-size "12px"
color "#fff"
(" ul#sidenav"
(" li"
blah "blah")))))
Have a nice day!I'm currently maintaining/developing on a 10yo Java project which contains a mix of JSP pages and ECS^-generated HTML in servlets. Which one is easier to maintain? The JSP pages by a mile because there is a direct correspondence between the source and the output. The ECS-generated HTML is totally obscured within the Java code.
So while HAML and SASS (to a lesser extent due to the similar syntax) abstract us programmer from the limitations of HTML & CSS, I can't help feeling that they will create huge maintenance headaches for our future-selves. Will anyone actually know HAML in 5-10years time? So, suck it up and use ERB and keep your abstractions as close to Earth as possible.
^ Apache ECS (now EOL'd) lets you build the HTML tree as nested Java objects.
Abstraction itself is not bad thing. Knowing that a lot of the technologies that we're using today will be obsolete in 10 years is not a good enough reason to stop trying new things.
CSS, however, is the fun where the true art of front-end design happens, so I think it's fun to play with a forgiving syntax.
It's fun to play with a forgiving syntax, but it's no fun saying the same thing 50 times.
That's why I like LessCSS (more than SASS anyway): LessCSS just feels like future CSS, a better CSS. Not something different, not something complex (it adds 4 basic features to CSS), it's a simple mechanical transformation and the output is easy to predict (I'm not fond of the &-combinator, but that's about the only criticism I have for it).
That said, there's a difference in tone between saying, "Haml is awesome, I love it, check it out!" (enthusiastic) and "Erb sucks, don't use it." (harsh)
Most Haml people I've seen/read seem to adopt the former tone, while most anti-Haml people adopt the latter tone. YMMV of course.
I may have missed my mark in the writing because my point isn't to say that HAML sucks; my point is to say that there are logical reasons to decide NOT to use HAML just as there are logical reasons TO use HAML. What I was tired of is the assumption that HAML is simply universally superior and anyone who doesn't use it only does so because they don't "understand" HAML.
We have the facts and we're saying ERB. ;)
HTML imposes this very strict structure: tags must be closed properly. Sure, browsers can handle tag soup to varying degrees, but it's a very bad idea to have your app render invalid markup. Humans are terrible at ensuring all tags are closed properly. Computers are great at it.
When templating HTML, I prefer to use a tool the was specifically designed for HTML. HAML auto-closes tags for you. Erector (http://erector.rubyforge.org/index.html) is probably my favorite, as it auto-closes tags, allows you to write your views in pure ruby, brings the power of OOP to your views, and gives you a far more clean, testable view layer. Want to test your view? Simple: instantiate the view class with the necessary arguments, render it, and make assertions about the output.
%p Hello,
%strong World
!
When what Haml recommends is: %p Hello, <strong>World</strong>!
If it seems like you are fighting Haml, check the docs and the mailing list. There is a good chance there is another way to solve the problem. :markdown
Hello, **World**!However, I fail to see why that's a problem. HAML is an abstraction that explicitly acknowledged it is leaky. It just doesn't support inline markup; you'll have to fallback to html to get, just like you have to fallback to assembler from C or JNI from Java to be able to do certain things. I say that's a good thing. Draw a clear line.
Like what?
I have never bumped into anything haml wouldn't let me do. Does the author know that he can embed raw HTML with :plain and friends? (which, btw, are very rarely needed in practice)
I also wanted more specifics though, I felt like this was a fine opinion piece but lacked any specific world lessons.
- conditionallyNested = capture do
.foo
.bar
baz
- if f(x)
.wrapper
= conditionallyNested
- else
= conditionallyNested
Personally, I prefer this over duplicating the condition: <% condition = f(x) %>
<% if condition %><div class="wrapper><% end %>
<div class="foo"
<div class="bar">
baz
</div>
</div>
<% if condition %></div><% end %>
However, you can trivially abstract my first example out into a helper and result in code looking like this: = wrap_if f(x), :class => 'wrapper' do
.foo
.bar
baz
Much nicer looking, in my opinion. I don't consider this a workaround at all.While I prefer HAML to ERB, I understand that occasionally wrapper divs can be a hassle in HAML. I assume this is what you're alluding to in Breadth and Scope, but maybe there is more?
The point of this post may not have been to add clarity for people not familiar or already opinionated, but if it was, the more specifics the more helpful it'd be for someone like me.
I have only superficial knowledge of SASS and JQuery, but it seem to me that can you do the same things with both?
SASS manipulates the CSS in a precompilation step. JQuery mainipulates the CSS at runtime.
Are there any considerations when choosing between both?