TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

I don’t like the Ruby 1.9 hash syntax

46 pointsby mshafrirover 13 years ago

12 comments

chcover 13 years ago
This is such a superficial argument — even more superficial than the feature it's criticizing. It's only <i>possibly</i> misleading if you aren't familiar with the syntax, and that's true of a whole boatload of things, such as block syntax. The hashrocket itself looks bizarre and excessively noisy to people coming from JavaScript or Python or pretty much anything but PHP.<p>This really is just, "I am not used to this syntax, so it looks weird to me." It's the same argument some people make against calling methods without parentheses in Ruby. If you're the sort of person who writes "self.houses().map(){|house| house.sale_price()}.sort()", then I guess at least you're being consistent. If not, don't be that guy.<p>More philosophically, Ruby is a TIMTOWTDI language. There are five different and largely interchangeable ways to create a Proc, half the core library methods are aliases for other methods, several keywords are just slight variations on each other for no purpose other than to give you options, you can take or leave parentheses, etc. The new hash syntax is just one more example of this ethos. If this embarrassment of ways to write any given program bothers you (and you're certainly in good company if it does), you'd probably be more at home with Python. (I don't mean to tell anyone their business, I'm just saying, "only one way to do it" is the Python philosophy.)
评论 #3350749 未加载
评论 #3350515 未加载
评论 #3350660 未加载
jcromartieover 13 years ago
Clojure made me realize that both of these styles are silly. Why do you need hashrockets, colons, or even <i>commas</i>? Why do you need a key/value separator AND a pair separator?<p>They might be useful as separators sometimes, but why are the absolutely required? They seem like noise. Anyway... I'll stick with hashrockets because the colon at the end is just confusing.
评论 #3350369 未加载
评论 #3350394 未加载
ScotterCover 13 years ago
My issue with the new syntax is bringing other people up to speed. Two syntaxes for the same functionality can be confusing <i>especially</i> when it's similar to another language such as javascript. I, a rubyist for a whole year and a half now (sarcasm), thought it had something to do with only JSON at first glance. I myself will be sticking to the hash rocket.
Argorakover 13 years ago
A bit of history: this syntax originally appeared in MacRuby and is used for the named parameters needed to call ObjectiveC methods:<p><pre><code> person.setFirstName(first, lastName: last) </code></pre> So, introducing it into Ruby 1.9 gave MacRuby the ability of hooking into valid ruby syntax to do its special thing.<p>As a wild speculation, it may also be used for named parameters, should they ever be introduced in Ruby.<p>Personally, i like it for exactly that case. I do not like it as a generic hash syntax for another reason: its easy to align the =&#62;, but its hard to align the:.
chealdover 13 years ago
I don't think I like it either, but I'm pretty sure it's just because colons are already very commonly used in hashes as symbol delimiters.<p>{foo: :bar} just feels <i>weird</i>.<p>It's not a world-ending issue - certainly not enough to make an effective difference in practical usage - but it's enough of a visual collision that it rubs me the wrong way.
damncabbageover 13 years ago
My only misgivings about the new syntax is that these sorts of lists now look rather dumb:<p><pre><code> foo: :bar, baz: :quux, wub: :bozo </code></pre> (This is, admittedly, a very subjective complaint. We could start calling this new double-colon syntax collision "Paamayim Nekudotayim".)
euroclydonover 13 years ago
As someone with no Ruby experience, I was reading through the lasted RoR config files recently, and I encountering these key/vals separated sometimes by a comma, other times by a colon, sometimes by nothing with the colon on the wrong side. I had to research new Ruby syntax for an hour to figure it out.<p>If you are unfamiliar with Ruby symbols to begin with then it's tough on the brain because there is no discernible pattern.
jgavrisover 13 years ago
long live the<p><pre><code> { :hash =&#62; :rocket } !</code></pre>
jhrobertover 13 years ago
name: value instead of :name =&#62; value makes as much sense as p-&#62;q instead of (*p).x in C<p>As an historical note, here are the message (and matz’s response) where I made a proposal for the new syntax, back in 2002. It includes rationals.<p><a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/38391" rel="nofollow">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/...</a><p>Matz’s response : <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/38402" rel="nofollow">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/...</a>
nagnatronover 13 years ago
Just don't use it. I won't.
tzsover 13 years ago
OnSwipe warning.
zapadapaover 13 years ago
ruby is retarded.
评论 #3350924 未加载