What is your style? ':this_style =>' vs 'this_style:' or depends?

53 views
Skip to first unread message

Brandon

unread,
Mar 20, 2014, 5:27:41 AM3/20/14
to rubyonra...@googlegroups.com
I noticed Michael Hartl's tutorials seem to use this ':this_style =>' more. What is your take on this?

Walter Lee Davis

unread,
Mar 20, 2014, 9:48:44 AM3/20/14
to rubyonra...@googlegroups.com
They both work, it's just a matter of personal style. I find that I get confused easily with the whatever: style, I start to think in terms of CSS and my Ruby brain shuts down.

Walter

On Mar 20, 2014, at 5:27 AM, Brandon wrote:

> I noticed Michael Hartl's tutorials seem to use this ':this_style =>' more. What is your take on this?
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5ee9a6e7-d09c-43cb-a9e6-74e04adf0d61%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Robin Solanki

unread,
Mar 20, 2014, 10:51:37 AM3/20/14
to rubyonra...@googlegroups.com
Agree with Walter its the matter of your preference but I do prefer the
new style without the rocket.

--
Posted via http://www.ruby-forum.com/.

Dave Aronson

unread,
Mar 20, 2014, 8:32:27 PM3/20/14
to rubyonrails-talk
On Thu, Mar 20, 2014 at 5:27 AM, Brandon <wong...@gmail.com> wrote:

> I noticed Michael Hartl's tutorials seem to use this ':this_style =>' more.
> What is your take on this?

I prefer the newer "key: value" style -- partly because I work with
JSON frequently, so this way is consistent. Other than that, ask five
devs and you'll get seven opinions....

-Dave

--
Dave Aronson, freelance software developer (details @ www.Codosaur.us);
see also www.PullRequestRoulette.com, Blog.Codosaur.us, www.Dare2XL.com

Vladimir Rybas

unread,
Mar 20, 2014, 8:45:41 PM3/20/14
to rubyonra...@googlegroups.com
In the [Github Ruby Styleguide][1] there's a note about Hashes:

`Use hashrocket syntax for Hash literals instead of the JSON style
introduced in 1.9.`

I guess the reason is that if you use hashrocket syntax, you can use
any type as a hash key, while with colon the keys are `Symbol` only.
So, you'll (pretty much) always have two styles in your app.

Strict styleguides are important. What if we all start to do crazy
things like `@VARIABLE` or `CamelCaseConstant = [1, 2, 3]`? (and I've
seen such cases, unfortunately).

But in this particular case with hashes, I personally use mixed style.
So, colon for simple key-value hashes, where value is not a `Symbol`
itself. And hashrocket for mixed DSL hashes with "complex" values.


tamouse pontiki

unread,
Mar 20, 2014, 11:51:14 PM3/20/14
to rubyonra...@googlegroups.com
I have been generally following the GH style guide, but not the
hashrocket thing, unless a client mandates it. One thing to note:
Github itself as a huge codebase, the main site still runs Rails 2.x,
and it makes sense when you have a long term code base, to keep a
consistent style across it. I'm not so sure that one needs to be so
slavish to that though if you aren't writing code for GH.

Brandon

unread,
Mar 24, 2014, 9:48:16 AM3/24/14
to rubyonra...@googlegroups.com
Visually I find the hash rocket style really unnerving.. I don't know why! Just like the "<<" which is supposed to be more efficient than "+". Just pains me to see them but I'm trying to adhere to best practices too.
Reply all
Reply to author
Forward
0 new messages