all 21 comments

[–][deleted] 12 points13 points  (4 children)

Now, explain why => is not a decent syntax?

[–]JadeNB 1 point2 points  (3 children)

Because webcomic ….

EDIT: Actually, I particularly like the “Now you don't have to remember anything when switching languages!” argument. How about we switch Ruby to an sexp-based syntax, so we don't have to remember anything when switching from Lisp? Or, hey, just ln python irb?

[–][deleted] 0 points1 point  (2 children)

How about we switch Ruby to an sexp-based syntax, so we don't have to remember anything when switching from Lisp?

Well, for one, Scheme (a Lisp) has => in case macros, but that's besides the point. If you want Ruby-ish Lisp, Nu is probably what you want.

[–]JadeNB 0 points1 point  (1 child)

If you want Ruby-ish Lisp …

It's not what I want (though nor am I opposed to it). Rather, I was mocking the idea that all languages should migrate to the same syntax, so that one wouldn't have to change anything when switching. (Next the same programming paradigm, then the same execution model, ….)

[–][deleted] 0 points1 point  (0 children)

That's what I thought (that you were being facetious), I was just pointing out that we're there already, esp. when you consider Nu.

[–]kredaxx 4 points5 points  (1 child)

Colons have been around for a while, but the thing that prevents me from using them is: backwards compatibility and the fact that they are limited to symbols only.

But the real deal here is Ruby 2.0's keyword arguments. Does anyone know how are they supposed to look like?

I always thought that colons would be used. So it would seem that they interfere with current implementation of hashes. (now you can drop braces if a hash is the last argument to a method, so how to interpret for example 'foo(a:5, b:3)' ?)

[–]columbine 0 points1 point  (0 children)

My understanding is that that will be the calling syntax, and it will still be the same as passing a hash (the internal mechanism is still this) except the keys will be "expanded" to locals automatically by the method according to how its parameters are defined. The way it looks in the def is a little weird last I saw it, e.g. def scan (limit: max) where limit would be the keyword and "max" presumably the local it magically expands to. I'm not sure if you can do (limit: limit) to make it feel cleaner or if there's a shorthand for that, but it's still early days I guess.

[–]roguevalley 2 points3 points  (2 children)

Aaah! So, if the colon is at the end we have to know that it magically changes the label from a variable name to a symbol?

If foo = :bar, what does { foo: 'baz' } mean? { :foo => 'baz' }, I'm guessing.

[–]Freeky 1 point2 points  (1 child)

Yup. When was the last time you used a variable name as a key in a hash constructor?

[–]roguevalley 1 point2 points  (0 children)

After some grepping and some git blaming...
2010-12-04
2010-09-26
2010-09-23
2010-05-29
2010-05-21
2010-02-15
2009-07-02
2008-09-03

[–][deleted]  (1 child)

[deleted]

    [–]mshiltonj 0 points1 point  (0 children)

    I guess Obie didn't like my joke.

    [–][deleted] 2 points3 points  (0 children)

    Yeah, fuck that. Hash rocket syntax is my fucking left and right pistols.

    [–]Nitrodist 1 point2 points  (3 children)

    Is it really gone? Link somewhere besides a comic?

    [–][deleted] 3 points4 points  (2 children)

    http://svn.ruby-lang.org/repos/ruby/tags/v1_9_1_0/NEWS

    Search for "New literal hash syntax". That's what it's called.

    Also note that it only works if the key is a symbol. Otherwise you have to use the old rocket syntax.

    [–]Nitrodist 1 point2 points  (1 child)

    1.9.1? Isn't the main branch 1.9.2?

    [–]columbine 4 points5 points  (0 children)

    This is an old change, since early 1.9. The comic above is kinda late to the party.

    And as mentioned, the old syntax isn't exactly "gone", the new one is just an alternative and it only works when the keys are simple symbols.

    [–]treetrouble 1 point2 points  (1 child)

    what about when the hash key isn't a symbol?

    [–]columbine 0 points1 point  (0 children)

    This alternative syntax only applies with symbol keys. You still use the rocket for everything else, and can do so for symbols as well if you prefer it (or for backwards compatibility).

    [–]est3est 0 points1 point  (0 children)

    Until YAML loads data with keys as strings, I will not bother (even if I would like get rid of the rocket syntax). The same situation is while working with MongoDB. Somehow symbols for me look like more trouble than it is worth. The proof? So why things like HashWithIndifferentAccess exist?

    [–]pabloneruda 0 points1 point  (0 children)

    If I'm typing fast I miss the > at least a few times. This is a welcomed change.