4 ms·
"I’m not sure why Ruby doesn’t have named parameters yet (See disclaimer up top on my ignorance), but the language certainly seems alive and active, in that per
by rbxbx 16y ago
"I’m not sure why Ruby doesn’t have named parameters yet (See disclaimer up top on my ignorance), but the language certainly seems alive and active, in that perhaps the next version will?"
Matz stated during his keynote at Rubyconf 2010 that Ruby 2.0 would have proper named parameters for methods, although in practice they will be largely the same as they are now.
- daviding 16y agoAh, thanks for that. I thought I might have missed them, but the symbols/hash convention is something I'm growing used too.
- Andys 16y agoAnd hashes with symbol keys became a bit nicer in 1.9: Account.create(:firstname => 'Bob', :lastname => 'Smith') # old Account.create(firstname: 'Bob', lastname: 'Smith') # new
- regularfry 16y agoI've got to say, that's probably my least favourite of the new syntax changes. It adds a new, context-specific syntax for both symbols and associativity, hiding what's actually going on in the method call, to save 3 characters per parameter. That's a fair cognitive load and backwards-compatibility problem in exchange for a relatively minor typing and readability gain. Maybe I'll get used to it, but it doesn't seem worth the change to me right now.
- ollysb 16y agoIt does seem very much like a kludge to get pseudo named parameters working. It would be great to see this dropped as a hash syntax and used for only named parameters in 2.0. The genie does seem to be out of the bottle though :(
- rbxbx 16y agoAfter using Ruby 1.9.2 for a few months now the new/alternate hash syntax has grown on me quite a bit, especially for keyword arguments. It typically ends up being much more readable (unless your value is a symbol (key: :value) reads awfully). If you don't like it though, there's no reason to use it yet.