3 ms·
Ruby 1.9 hash literal syntax was introduced as an evolutionary step toward keyword arguments. If the former didn't exist, the latter would be a special syntax s
by djur 8y ago
Ruby 1.9 hash literal syntax was introduced as an evolutionary step toward keyword arguments. If the former didn't exist, the latter would be a special syntax similar to but incompatible with the existing idiom to use a hash in terminal argument position as keyword arguments. That is, without the ability to treat foo(:a => 1, :b => 2) as equivalent to foo(a: 1, b: 2), you end up with two versions of every API -- "hash kwargs" and "real kwargs". And you'd similarly lose the ability for existing APIs to migrate to explicit keyword arguments from hash kwargs.
Would I prefer it if Ruby had started out with Crystal's named argument syntax? Absolutely. But Crystal had the luxury of starting from scratch without any need for backwards compatibility.
- DarkWiiPlayer 8y agoI think Rubys vararg syntax is terribly unintuitive and inconsistent though.
- djur 8y agoIt is, but it was also a compromise meant to maintain compatibility with existing code. And I mentioned it specifically because the OP identified keyword arguments as a good new feature but the new hash syntax as bad.
- Jenz 8y agoCrystal is very exiting ATM, next release is scheduled to come with multithread preview.