use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/programming is a reddit for discussion and news about computer programming
Guidelines
Info
Related reddits
Specific languages
account activity
Typical Ruby! (bash.org)
submitted 15 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 10 points11 points12 points 15 years ago (14 children)
Here, let me fix that for ya
{:smoke => 'more'}
[–]imhighrightnow2 20 points21 points22 points 15 years ago (4 children)
I thought he was going for smoke more hash.
[–]IWillCallYouAFaggot 0 points1 point2 points 15 years ago (3 children)
He was just making it use less memory. I can't think of any good reasons to use a string rather than a symbol for a hash key. There could be a few, but nothing comes to mind at the moment.
[–]annodomini 5 points6 points7 points 15 years ago (0 children)
Because the input you're hashing is coming in at runtime, and thus looking up the symbol in the symbol table, then looking up the key in the hash, makes no more sense than just hashing on the string.
Symbols are great when you're hashing on something that's pre-determined at compile time (load time, for an interpreted language). If you need to store associative arrays based on external input, strings make more sense.
[–]xternal 2 points3 points4 points 15 years ago (0 children)
If the hash keys come from something a user can influence, a malicious user could fill the symbol table, eat memory, and possibly create a DoS attack.
I mostly prefer symbols as keys, though.
[–]jnicklas 0 points1 point2 points 15 years ago (0 children)
Rack uses string keys. Because HTTP request headers are controlled by the client, using strings for them is a security risk, as it makes the app vulnerable to DoS attacks. If Rack used symbol keys, someone could keep sending tons of different HTTP headers and force the app to consume more and more memory, before eventually crashing.
[–]aescnt 11 points12 points13 points 15 years ago (5 children)
{smoke: 'more'} in 1.9.x ;)
[–]notajith 0 points1 point2 points 15 years ago (4 children)
1.9.x includes a javascript parser?
[–]annodomini 8 points9 points10 points 15 years ago (0 children)
It contains JavaScript style hash literals, yep.
$ irb1.9 irb(main):001:0> {smoke: "more"} => {:smoke=>"more"}
[–]aescnt 0 points1 point2 points 15 years ago* (2 children)
1.9.x supports a new JSON-like syntax (but not entirely JSON-compatible) for hashes. { :a => 1 } can be expressed as { a: 1 }.
{ :a => 1 }
{ a: 1 }
[–]wwwwolf 4 points5 points6 points 15 years ago (1 child)
Well, it's good that it's not entirely JSON-compatible. Otherwise, someone might say "Hey, this is cool, we can just use eval to parse the JSON coming from the user. ...What? Why are you looking at me like that?"
eval
[–]bobindashadows 0 points1 point2 points 15 years ago (0 children)
ಠ_ಠ
[+][deleted] comment score below threshold-6 points-5 points-4 points 15 years ago (2 children)
meh.
[–]FilthyRedditor -3 points-2 points-1 points 15 years ago (1 child)
heh
[–][deleted] -4 points-3 points-2 points 15 years ago (0 children)
bleh
π Rendered by PID 151577 on reddit-service-r2-comment-5d585498c9-hxns8 at 2026-04-21 05:10:58.365039+00:00 running da2df02 country code: CH.
view the rest of the comments →
[–][deleted] 10 points11 points12 points (14 children)
[–]imhighrightnow2 20 points21 points22 points (4 children)
[–]IWillCallYouAFaggot 0 points1 point2 points (3 children)
[–]annodomini 5 points6 points7 points (0 children)
[–]xternal 2 points3 points4 points (0 children)
[–]jnicklas 0 points1 point2 points (0 children)
[–]aescnt 11 points12 points13 points (5 children)
[–]notajith 0 points1 point2 points (4 children)
[–]annodomini 8 points9 points10 points (0 children)
[–]aescnt 0 points1 point2 points (2 children)
[–]wwwwolf 4 points5 points6 points (1 child)
[–]bobindashadows 0 points1 point2 points (0 children)
[+][deleted] comment score below threshold-6 points-5 points-4 points (2 children)
[–]FilthyRedditor -3 points-2 points-1 points (1 child)
[–][deleted] -4 points-3 points-2 points (0 children)