Live data from Hacker News

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

blog.peepcode.com

11–20 of 95 posts

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

#11
post #5

also says this syntax is compatible with python which is not really true. if you have this in python: { key: "value", dr_nic: "The Comedian", ttl: 42 } python will expect there to be a variable called 'key', one called 'dr_nic', and one called 'ttl'. If you intend to do d['ttl'] you'll need to create a hash using a literal string

You don't necessarily have to create a hash using a literal string. You can also do this:

    dict(
        key="value",
        dr_nic="The Comedian",
        ttl=42
        )
...but that is a bit different syntax.

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

#15
post #10
post #6

Earlier quoted context omitted.

Ruby 1.9 still uses hash rocket. I'm using RoR3 on 1.9.2 and I haven't changed any of my hashes. I guess if you want to save some key strokes and you use symbols as keys you can use the new syntax. The other cool/different thing about Hash in 1.9 is that it preserves order.

[deleted]

Ouch. Thanks for pointing that one out.

PS. Ruby 1.9 does have a native OrderedHash, the same as the one from ActiveSupport.

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

#17
post #10
post #6

Earlier quoted context omitted.

Ruby 1.9 still uses hash rocket. I'm using RoR3 on 1.9.2 and I haven't changed any of my hashes. I guess if you want to save some key strokes and you use symbols as keys you can use the new syntax. The other cool/different thing about Hash in 1.9 is that it preserves order.

[deleted]

Actually, insertion order preservation is a 1.9 feature:

> Hashes enumerate their values in the order that the corresponding keys were inserted.

from http://www.ruby-doc.org/core/classes/Hash.html

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

#18

I think they won't be removing hashrocket anywhere before 2.0, so you may use whatever you like better.

I think people are misunderstanding the title (which is not meant to be taken literally). They won't be removing the hashrocket ever, since (surely) they don't plan to limit hash keys to symbols only. The syntax only works in limited cases (namely symbols without spaces).

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

#19
post #5

also says this syntax is compatible with python which is not really true. if you have this in python: { key: "value", dr_nic: "The Comedian", ttl: 42 } python will expect there to be a variable called 'key', one called 'dr_nic', and one called 'ttl'. If you intend to do d['ttl'] you'll need to create a hash using a literal string

Yea. So they've move away from the Perl-like 'rocket' syntax to a more JavaScript/Python-like syntax. Ruby+Python hackers will rejoice while Perl+Ruby hackers will pout. This isn't necessarily some 'huge' win.

[Though I guess it could be a 'win' for Rails hackers since they are likely to just be Ruby/Rails+JavaScript hackers.]

Post reply on HN