Live data from Hacker News

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

blog.peepcode.com

71–80 of 95 posts

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

#71
When I was looking at the page, I noticed that the example:

{

  key: "value",

  dr_nic: "The Comedian",

  ttl: 42
}

didn't seem to use the :symbols I know but omitted the colon.

Turns out, it somehow works:

> a = {my_key: "my_value"}

=> {:my_key=>"my_value"}

Has this always been there? It's kinda weird because that way they look like regular variables O_o

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

#72

I have to say I cried a little bit when I read this - it seems that Matz et al are trying to make the language unparseable. (Of course, perhaps I'm more sensitive than most, having actually written an Ruby lexer - http://github.com/jasonl/eden - which made me deal with the dusty, hidden corners of the Ruby grammar.)

Only ruby will be able to parse Ruby ;-)

Ruby is just showing its Perl roots.

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

#74
post #62
post #61

Earlier quoted context omitted.

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

You can do it, but is it a good idea? What it implies to me is that at some point in your program, you're constructing symbols from arbitrary strings which aren't known ahead of time. This sounds like a recipe for disaster given that symbols aren't garbage collected.

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

#76
post #50
post #8

Cool. Now why doesn't PHP join the crowd and do this with arrays already?

[NSArray arrayWithObject:notToMentionObjectiveC];

shudder

Having written and shipped 5+ iPhone apps written in the verbosphemy* that is ObjectiveC, I'm strongly looking forward to being able to do all future iPhone apps in a saner language like JavaScript or Python. If I do them at all. Ever again. In fact it's pretty much a hard requirement. Just after this current one ships.

(*: verbose + blasphemy)

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

#78
I prefer the "hash rocket" (I call it the fat comma), because it looks nicer when you have a hash with keys of varying length. Compare:

    {
        foo: 'bar',
        hello_world: 'OH HAI',
    }
to

    {
        foo         => 'bar',
        hello_world => 'OH HAI',
    }
If you try to do that with colons, it goes all wonky:

    {
        foo         : 'bar',
        hello_world : 'OH HAI',
    }

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

#80

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'}

You can also use "HTML-style attributes" [1]

    #main_page(data-role='page')
[1] http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#ht...
Post reply on HN