-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do not enforce hash rockets, prefer 1.9 hash literal syntax #342
Conversation
You lose the ability to quickly see if you're passing a hash or passing keyword arguments this way. |
Hash rocket style was enforced due to personal flavors. I don't find new hash syntax worth using it. { :foo => { "Bar" => 123 } }
# looks more consistent than:
{ foo: { "Bar" => 123 } } |
Thanks for the efforts, but I am pretty strongly against this change. Until hash-rocket will become deprecated - I don't see any good reason to switch to the new style. |
Re: rubocop defaults. I find some of it's code style defaults to be pretty stupid. |
No problem! Thanks for your time @ixti! 😸 |
For what it's worth, I like the new syntax 😜 |
Haha yea I'd +1 on liking the new syntax, but also it's becoming more common so having inconsistency seems a little odd. |
Since we’re all weighing in on hash syntax, I prefer the classic rockets, since they can be used consistently (regardless of key type) and are less ambiguous. POP QUIZWhat is the result of the following statement? {"foo": "bar"} It looks like the key is a string but it actually gets converted to a symbol, unless you’re using Ruby 2.1 or earlier, in which case it produces a The hash rocket syntax will not be deprecated until the colon syntax can handle non-symbol keys, which would be a breaking change in cases like |
I use the colon syntax and keyword arguments pretty frequently now, in addition to hashrockets. The style is basically this: Want a hash with symbols as keys or kwargs? Use the new syntax. Re: hash vs kwargs, this lets you retroactively upgrade APIs that previously took options hashes to use kwargs. Switching from options hashes to kwargs gives you better runtime checking in terms of the arguments passed (e.g. unknown kwargs are automatically an error), so I see this as a benefit instead of a problem. We just phased out 1.9 support, so "upgrading" our APIs to kwargs is a (mostly) backwards compatible option (although it would break users passing bogus options). There are a few places I feel the syntax "leaks" in practice, specifically around the quoted symbol syntax @sferik was talking about. The biggest problem I've encountered is wanting to have keys which contain a
|
Since support for 1.8.7 is long gone, and since all supported versions of Ruby support keyword args, it seems like a good time to prefer the use of the 1.9 alternate hash literal syntax, enforced by default by Rubocop.