-2

Where did it come from?

Why didn't they use -> or some other notation?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
B Seven
  • 44,484
  • 66
  • 240
  • 385
  • 9
    Because with '->' it could only be monorails! ..er...sorry. – rjz Mar 12 '12 at 02:07
  • 1
    Why would it? If you have problems with => be happy that you can now do {sym: 1} instead of {:sym => 1} – Ismael Abreu Mar 12 '12 at 02:07
  • Oh my god rjz. I think I love you. – DanRedux Mar 12 '12 at 02:08
  • 7
    The `=>` notation most likely came from Perl's "fat comma" (also `=>`), they're both used for the same thing. But this isn't the right place for questions like this. – mu is too short Mar 12 '12 at 02:09
  • @ismaelga: But the JavaScript style isn't always an option, Hashes can have any objects as keys and if you're going to use MongoDB you'll have to use `=>` for things like `:$set => { ... }` as `$set: { ... }` is a syntax error. – mu is too short Mar 12 '12 at 02:11
  • @muistooshort Yes, it's not always possible, but in most cases when you need to represent a Hash in code you use symbols. And thanks, I didn't know about that detail on MongoDB, haven't tried yet with ruby. – Ismael Abreu Mar 12 '12 at 02:17
  • Indeed I think it's from Perl as mu is too short write, and I think that is for visual appearance. `=>` looks more like an arrow than `->`. – sawa Mar 12 '12 at 02:21
  • 1
    @muistooshort thanks for your comment, but what's the rationale? So long as this answer is about programming rather than programmers, and has an objective answer, I don't see why it shouldn't be asked here. – Andrew Grimm Mar 12 '12 at 21:12
  • @AndrewGrimm: This doesn't seem to fall under "practical, answerable questions based on actual problems that you face" and "not constructive" seemed like the closest match. I don't think SO is the right place for this sort of thing, a Ruby mailing list would be better and four other people agreed with me. I did offer the most likely answer as well as voting to close (which I do a fair bit). – mu is too short Mar 12 '12 at 21:21

2 Answers2

3

So when they use ->, will you ask why does Rails(actually not Rails bu Ruby) use ->, and why not =>?

By the way, the new lambda syntax in Ruby 1.9 use ->.

xdazz
  • 158,678
  • 38
  • 247
  • 274
1

Faster interpreting. The => is not ever going to be used anywhere else, -> may be, making it quicker to decide what to do with as you parse the script.

DanRedux
  • 9,119
  • 6
  • 23
  • 41