The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From: Piotr Szotkowski <chast...@chastell.net>
Date: Tue, 31 May 2011 05:55:39 +0900
Local: Mon, May 30 2011 4:55 pm
Subject: [ruby-core:36596] Re: [Ruby 1.9 - Feature #4801][Open] Shorthand Hash Syntax for Strings
> I though exactly the same thing, until I realized Why? [citation needed] > that having keys of different types in a Hash > isn't really part of the general Hash concept. > Consider the following: Well, they either do or don’t, then. :) > { nil => 0, :foo => 1, 'foo' => 2 } > Conceptually, people expect Hash keys to be of the same type, > except maybe for "hacks" like that nil above that can simplify code. > If someone out there in the world actually demands that such a Hash Hm, IMHO ‘any object can be a key, just as any object can be > is valid and that :foo and 'foo' are different keys, you could always > wrap Hash to support that for that single, specialized case. a value’ is the general case, and ‘I want my Strings and Symbols to be treated the same when they’re similar, oh, and maybe with the nil handled separately for convenience’ is the specialised case. > In Ruby "foo" + 123 raises a TypeError. Adding a string I don’t see why it should – as long as it still > key to a symbol-keyed Hash doesn't even show a warning. responds to #hash and #eql?, it’s a valid Hash key. Hashes in Ruby serve a lot of purposes (they even maintain insertion > I consider hashes with different key types different types of hashes, There’s nothing preventing you from subclassing Hash to > that shouldn't even be allowed to merge together without conversion. create StringKeyHash, SymbolKeyHash or even MonoKeyHash that would limit the keys’ class to the first one defined. How would you treat subclasses? Let’s say I have a Hash with What about String-only keys, but with different (For discussion’s sake: what about if a couple of the Strings > I think the meaning of symbols and hashes are too similar for such But that would introduce a huge exception in the current > different types to be allowed as keys in the same Hash instance. very simple model. Ruby is complicated enough; IMHO we should strive to make it less complicated, not more. — Piotr Szotkowski
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| |||||||||||||||||