martes, 13 de abril de 2010

Improve your code with Haml/Mejora tu código con Haml






In English

Hamles un lenguaje de marcado que me gusto mucho por dos o tres motivos principales.

1 - Escribis menos: cada tag que generes, ya sea un form, div, span, etc no necesita
ser cerrado como cuando utilizas html.

2 - Correcta identacion: te obliga a tener el código ordenado por lo que podría ser
bueno si trabajas con un diseñador gráfico que tenga el coraje/ganas de aprender
este markup. No debería llevar tanto tiempo de aprendizaje y los beneficios tanto
para diseñador como desarrollador van a ser grandes a la hora de leer y entender el
código en vistas, partials, layouts, etc.

3 - Consecuencia de los dos puntos anteriores: Tu código sera menos extenso, tendras
una lectura mas rápida y clara, llegaras al punto que quieras en menos tiempo y con
menos esfuerzo de escritura/corrección de código, menos posibles bugs por mal cierre
de tags, codigo más limpio. En una palabra, te ayuda a ser un mejor programador,
aunque tu puedes hacer y deshacer algo que quizás otro programador lo haría de forma
mas simple, pero eso ya es otro problema.

Yo estoy utilizando este lenguaje en aplicaciónes Rails desde hace un corto tiempo,
pero pienzo seguir implementandolo para futuros desarrollos mientras no haya un
diseñador/jefe que se oponga o resista al cambio. Sino, sera cuestión de demostrar
cuales son las razones por las que sería bueno utilizarlo.

Por lo que vi existen para otros lenguajes algunas herramientas inspiradas en Haml
como Ghrml para Python, Fammel para Php, Scalate para Scala o NHaml
para .Net






En español

Haml is a markup language that likes me for two or three mainly reasons.

1 - Write less: each tag that you make, whatever be, a form, div, span, etc doesn't
need be closed like when you use html.

2 - Correct indentation: you must have ordered code,thing that could be good if you
work with a graphic designer that has the courage/intentions of learn this markup
language. It should not take too much time of learning and the benefits for the
designer as the programmer too could be a big thing at the hour of read and understand
the code in views, partials, layouts, etc.

3 - As consequence of the first two points: Your code will be less extensive, a major
speed to read, reach the point that you want in less time and with less efforts of
write code, less possible bugs for bad close of tags, clean code. In one word, it
helps you to be a better programmer, although you could do and undo something that
maybe another programmer would be doing in a easier way, but this is another problem
for resolve, not a Haml problem.

I am using this language in Rails applications since a couple of weeks ago, but I
think I'll continue using this for future applications while there aren't
designers/bosses that reject to the change. But, i think that it will be only a
question of show the reasons 'why?' this is a good choice.

I saw that exist for another languages some tools inspired in Haml like Ghrml for
Python, Fammel for Php, Scalate for Scala or NHaml for .Net





First Pict: A form with .haml/Un formulario con Haml:





Second Pict: And with html.erb it should be write like this/ Y con html.erb debería
ser escrito así:


































Como puedes ver, en la segunda imagen tiene 10 lineas mas de codigo que en la primer
imagen y el código en la primer imagen solo funciona si esta identado, una buena
razon para ser ordenado no?!

As you can see, the second picture has ten lines more of code than first picture and
the code in first picture is indented or it won't work, a good reason to be ordered
to write code, no?!