Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

And 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


I'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.


After 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.


It 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 :(




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: