Which is better?
1.
= link_to "Page", "/page", :class => "button", :data => {:theme => "green", :icon => "small-arrow"}
2.
= link_to "Page", "/page", class: "button", data: {theme: "green", icon: "small-arrow"}
3.
= link_to "Page", "/page", class: :button, data: {theme: :green, icon: "small-arrow"}
I found out that the symbols are the best way to use because of the memory alocation difference between symbols and strings.
I find version 2. as more readable (for me) and i think also more maintainable, because it’s easier/faster to see/edit/add separated words (by space or dash) inside a string rather than edit a symbol and transform it to a string (when needed, like adding a second class “button login” or other theme “dark-red”, for example).
Is there any serious reason (e.g. performance) to use the notation from 1. or 3. rather than 2.?
Note that it’s not only about symbols, it’s about old and new hash syntax.
I don’t like to mix new hash syntax with symbols. New syntax looks well in most cases, for example:
But it looks horrible with symbols:
It is weird and not human readable, in my opinion. I dislike 3rd option. So, I prefer this option (you didn’t mention it):
This is better because
:classsymbol is written similar to:buttonsymbol. Symbols should be written in the same syntax in a single line.