haml, an objective view

In the last few weeks, I have been introduced to haml, which is a different way to write you views in rails. My initial thoughts about it weren’t so keen, so I wanted to take a more in depth look at it to see why people are switching to it, and why, or why not, to use it.

First of, I can see why people are switching to it. It is generally felt that it is a cleaner way to look at your views. For example, this is what something simple might look like in rhtml

<div id="profile">
 <div class="left column">
  <div id="date"><%= print_date %></div>
  <div id="address"><%= current_user.address %></div>
 </div>
 <div class="right column">
  <div id="email"><%= current_user.email%></div>
  <div id="bio"><%= current_user.bio %></div>
 </div>
</div>

The same code, done with haml would be

#profile
  .left.column
    #date=  print_date
    #address=  current_user.address
  .right.column
    #email=  current_user.email
    #bio=  current_user.bio

So, what is the first thing that you notice about the difference between these two? Well, the first one looks a lot like HTML with script tags, which is pretty much what it is. The second, looks a little bit like CSS at first glance. If we take a little closer look, we also see that in the haml example, there are no closing tages. What haml uses is very similar to python in that is uses white space checking to end things.

Some people enjoy this a lot, the fact that they don’t have to explicitly end things, but this is the first thing that bothers me about haml. It could just be the type of meticulous person I am, but I want to explicitly close things, and make sure that nothing is missed when programming. If I learned from python, I am pretty sure that this wouldn’t both me as much. Being that because I learned java as my first language, I even feel weird not explicitly using a return from a function (this throw me for a loop for a while in rails). I understand that this isn’t a very solid reason to not like something, but from a strictly person preference, I do not like this, however I do see where many would.

The second thing that bothers me about haml, is that a developer might not understand right away what it is doing. Many times have I worked with other people on projects at school, and a few programming contests, and what would mess us up the most is one of us not having the knowledge base for something and the other person trying to use skills and techniques that the other person doesn’t know. When doing some larger projects, many times the programmer will get a developer to do the views for the project, and then just fill in what they need to with script tags and the such.

Yes, I understand that at first glance, a developer might be able to read haml, and understand what is going on, but if you want to use haml for the entire application, they will need to learn how to write it. This may not be a big deal to some developers, but it might be to others. Basically when it comes to learning anything new, some people can pick it up quickly, but some might not be able to. I guess this maybe a moot point, but one I wanted to bring up none the less.

So, in doing a little bit more research between the two, I looked at what other people had to say about the two. There was really only one strong argument as why not to use haml, and it was due to the fact that it has to be reparsed before rendered and that it is a performance hit. Some metrics someone ran showed it at about twice as slow. This may not be a good argument for a lot of projects, but for those where performance matters, it is a very compelling argument.

So, personally, I don’t see a fantastic reason to want to switch to haml. I see its advantages of being cleaner, but also the disadvantages as well. I guess, I should try it on an app once, and see how I like it, and then use what works best for me because honestly, I don’t want to use something that is extremely uncomfertable for me, but if I happend to like it, then it might be something I would want to use more often. Once I give it a try, I will post my thoughts on it, but with the exception of the small things I don’t like about it right now, I can’t see a reason to dismiss it before trying it.

System.out.println(”Hello World”);

Greeting everyone. I would like to tell all of you a little bit about myself, and what this blog is about. For a while, I have been wanting to set up a blog, and now I finally got around to it.

First off, my name is Gary Crabtree, and I am currently a 22 year old college student at the University of Wisconsin Eau Claire. I am a computer science - software engineering major, and a psychology minor. This is the first place I ever learned any type of programming, and it all started with Java for me (hence the terribly tacky title). I have had a small taste of many languages, and design patterns, and that conglomerate of things that a computer science department will teach, but the most significant thing that has had an influence for me, did not actually come from class itself.

At first, I was slightly turned off to programming as it wasn’t what I thought it was going to be at all. Having never touched any code, with the exception of simple HTML, before college, going straight into the computer science department was a significant life choice for me. I had been good at the arts side of things. I was in choir, band, and theater, both musical and non musical, but I felt that why I enjoyed those things was because they were an escape for me from the “real world”. If I was going to go into any of those as a career, I think it would have lost its meaning to me. So, I figured I will always be able to find community theater, and choirs/bands wherever I go, and I decided to keep it a significant part of my life, but to pursue other endeavors.

I swayed my other options, and they came down to computer science, and psychology. So, I decided to go with computer science as a main focus as I felt that it would give me the best variety of options in careers after a degree with it. So, I proceeded to take classes at the university, homework outside of classes, and spending the rest of my time leisurely for a few years until one day, things changed.

I got a job for the university doing web development. I had done a bit of HTML as mentioned, and some simple things from classes as well, so I figured it would be a great way to earn some money as I was in need of some greatly. So, in the summer of 2007, I started said job doing simple static design work.  By the end of the summer however, I had started expressing interest in learning the application side of web design as well, and I proceeded to let me bosses know that if possible, I would like to move in that direction. So, towards the end of that summer, I started training in something that would greatly influence the rest of my college career, and undoubtedly, my life. What I speak of, is Ruby on Rails.

Once I started it, I didn’t understand why everyone advocated so strongly for it; it took me a good chunk of time before I would either. I didn’t get to fully do Rails work until almost that following summer due to other static projects that came up, and then I got to take another look at it. This time, I started to slowly see what was cool about it after a year of working with languages such as C/C++, Scheme, and Prolog in my classes. Slowly, over this previous year, I have gotten to spend a lot more time working with it, and it is leading me to stay with it in the future. Although I still have a lot to learn about it, I plan to continue working with it professionally when out of school as well.

I feel that I have gotten to tell you all about my story, and where I am coming from as well. This blog will be where I will talk about what I learn both with Rails, and other technologies either through school, work, or anywhere else.