Live data from Hacker News

R.I.P. Ruby Hash Rocket Syntax 1993-2010

blog.peepcode.com

61–70 of 95 posts

Re: R.I.P. Ruby Hash Rocket Syntax 1993-2010

#61
post #41

Interesting to see this convergence of syntax. Unfortunately, it's not true that you don't have to learn a "new syntax." As often with Ruby libraries, the devil is in the subtleties. This does not work (although I think it could): {"foo bar": 'b'} but this does: {:"foo bar" => 'b'} Without being truly JSON compatible, it's only moderately useful. One annoyance of Ruby for me has always been that many libraries, such…

Who would put a space inside the key name for an item in a hash?

I'm confident it's commonly understood best practice (among many languages at that) to use an underscore (_) in lieu of spaces in such things.

I agree that the quirks themselves are odd, but the matter of using a key with a space in it really stood out.

Re: R.I.P. Ruby Hash Rocket Syntax 1993-2010

#62
post #61
post #41

Interesting to see this convergence of syntax. Unfortunately, it's not true that you don't have to learn a "new syntax." As often with Ruby libraries, the devil is in the subtleties. This does not work (although I think it could): {"foo bar": 'b'} but this does: {:"foo bar" => 'b'} Without being truly JSON compatible, it's only moderately useful. One annoyance of Ruby for me has always been that many libraries, such…

Who would put a space inside the key name for an item in a hash? I'm confident it's commonly understood best practice (among many languages at that) to use an underscore (_) in lieu of spaces in such things. I agree that the quirks themselves are odd, but the matter of using a key with a space in it really stood out.

It's really common, actually. A symbol can actually have spaces in it:

:"Some Text" is a perfectly valid symbol.

ruby-1.9.2-p136 :001 > h = {:"Some Text" => 123} => {:"Some Text"=>123} ruby-1.9.2-p136 :002 > h[ "Some Text".to_sym ] => 123

Re: R.I.P. Ruby Hash Rocket Syntax 1993-2010

#63

In related news, Hashrocket (the consultancy) is alive and well, with no intentions of changing our name to Hashcolon. http://hashrocket.com/ In fact, like almost everyone else in our space we're looking to hire => http://hashrocket.com/jobs

Rebranding to "Colon" just isn't as sexy.

    :sex
Sex symbol, or colon sex?

Re: R.I.P. Ruby Hash Rocket Syntax 1993-2010

#65

Earlier quoted context omitted.

My own opinion is that although Ruby allows string-like symbols (like :"symbol with space"), I think they should be avoided. There may be a case for them, but I've not encountered one yet. The new syntax works only with conventional symbols (no quotes), not with any other key type, so no integers, strings, objects etc. For everything else, you can fall back to the original syntax. You can even mix then if you really…

Combining Haml with jQuery Mobile makes it pretty much mandatory: #main_page{:"data-role" => 'page'}

Haml keys can be plain strings.

    #main_page{"data-role" => 'page'}
`data-` attributes are also special-cased:

    #main_page{data: {role: 'page'}}

Re: R.I.P. Ruby Hash Rocket Syntax 1993-2010

#66
post #65

Earlier quoted context omitted.

Combining Haml with jQuery Mobile makes it pretty much mandatory: #main_page{:"data-role" => 'page'}

Haml keys can be plain strings. #main_page{"data-role" => 'page'} `data-` attributes are also special-cased: #main_page{data: {role: 'page'}}

I did not know that. Thanks for the heads up, and thanks for Haml and Sass!

Re: R.I.P. Ruby Hash Rocket Syntax 1993-2010

#67
post #61
post #41

Interesting to see this convergence of syntax. Unfortunately, it's not true that you don't have to learn a "new syntax." As often with Ruby libraries, the devil is in the subtleties. This does not work (although I think it could): {"foo bar": 'b'} but this does: {:"foo bar" => 'b'} Without being truly JSON compatible, it's only moderately useful. One annoyance of Ruby for me has always been that many libraries, such…

Who would put a space inside the key name for an item in a hash? I'm confident it's commonly understood best practice (among many languages at that) to use an underscore (_) in lieu of spaces in such things. I agree that the quirks themselves are odd, but the matter of using a key with a space in it really stood out.

When your key is a phrase, for instance? A hash of { phrase => count } is a pretty common data structure.

Re: R.I.P. Ruby Hash Rocket Syntax 1993-2010

#68

In related news, Hashrocket (the consultancy) is alive and well, with no intentions of changing our name to Hashcolon. http://hashrocket.com/ In fact, like almost everyone else in our space we're looking to hire => http://hashrocket.com/jobs

I imagine what you're looking for most is people for reliability and/or scaling?

The jobs link is down.

Post reply on HN