7 ms·
Syntax is hard. In general I think that adding a simple numbered argument access for blocks makes sense, and something like swifts $ syntax would look pretty na
by burlesona 8y ago
Syntax is hard. In general I think that adding a simple numbered argument access for blocks makes sense, and something like swifts $ syntax would look pretty natural, ie:
```
books.map { $0.title }
```
In the Ruby lang discussion on this they go through a dozen different possible syntaxes and they all have issues -- for example the $ is problematic because Ruby currently uses these for global variables.
Even so, IMO using the `@` symbol for this will make the language harder to learn. It's not a very nice thing to have syntax that is almost ambiguous to the human.
```
books.map { @prefix + @1.author }
```
I teach Ruby to a lot of engineers (of all different experience levels), and one of the nice things is that it's so easy to pick up and be productive quickly. But there are bits where it takes some practice, and I'm not looking forward to telling people, "The at sign means it's an instance variable. Well, except if you're in a block and it's @1 or @2 or something, in which case it's a positional argument." Oof.
- ololobus 8y agoI absolutely agree, interference with instance variable/method alias '@' looks awkward. For me it seems a little bit against Ruby-way.
- vidarh 8y agoInstance variables can not start with a digit, so this works fine from that perspective.
- jimbokun 8y agoSo another exceptional edge case to learn.
- vidarh 8y agoGiven how little of Ruby syntax most people know before they're able to read and understand Ruby, I don't see that as much of a concern. "@" suggests it's probably local of sorts, the number makes it clear it's not an instance variable, and the absence of |somevar| in a chained block will strongly suggest it's an argument, without having to know the precise details. There are many additions to Ruby I don't care much for, but this is one of the most intuitive I've seen.