From: Yorick Peterse Date: 2013-02-07T04:12:36+09:00 Subject: [ruby-core:51943] Re: [ruby-trunk - Feature #7792] Make symbols and strings the same thing > And "growing until you hit your memory limit" is actually only valid > for symbols, not for strings that are garbage collected already. > Unless you have some leak in your code that prevent those strings from > being collected by GC. Since existing code (and developers) assume that Symbols are only created once they are generally used all over the place without any side effects. The moment you start garbage collecting them there's an increased chance of the GC kicking in right in the middle of (say) an HTTP request. Yes, you may now be able to use both Symbols and Strings as Hash keys but you now have to deal with increased GC activity. Note that this of course depends on the code you're using. If you use carefully written code that doesn't use Symbols this is not going to be an issue. However, pretty every single Gem out there uses them and a lot of them also use them quite heavily. > Most of the programming languages don't support the concept of symbols > like Ruby. And you won't see C or C++ programmers complaining about > this neither C has a goto operator, does that mean Ruby should have one too (I'm aware it's already there, it's not just enabled unless you specify some compiler flag)? Just because one language has feature X it doesn't mean all the others should have it too. > Marshal is not portable across multiple languages (I use both Groovy > and Ruby in my overall application interacting with Redis). I'm > talking about JSON here. You don't have to find an alternative to > JSON. Just try to understand the issue I'm talking about., It wasn't suggested as an alternative, merely an example that there is a way of serializing arbitrary Ruby data. > Ok, I won't repeat myself. Please give an example for the Redis + > JSON serialization use case presented in the ticket description. > > Otherwise you cleared missed the point. Take a closer look at my previous Email, there's a fairly big example at the bottom of it that you can't really miss. However, just in case: require 'redis' require 'json' client = Redis.new client.set('user', JSON({'id' => 1, 'name' => 'John Doe'})) # This would happen somewhere else (e.g. an external process) hash = JSON(client.get('user')) user = User.new(hash) # instead of user['id'] you can now just do `user.id` which means # that if the key name ever changes you only have to change it in # one place. if user.id # ... end Another benefit is that this lets you attach your own methods to the object without having to monkeypatch existing classes or using helper methods (which feels very much like procedural programming). Yorick