From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id D329817CDC65 for ; Thu, 7 Feb 2013 03:39:25 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id B74ABEA6BF0 for ; Thu, 7 Feb 2013 03:22:39 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 9BC0F97A827 for ; Thu, 7 Feb 2013 03:22:39 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=gmail.com Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1JM8pbDv_sp7 for ; Thu, 7 Feb 2013 03:22:39 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 7854297A826 for ; Thu, 7 Feb 2013 03:22:39 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 34725952408 for ; Thu, 7 Feb 2013 03:22:39 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 49A953C229676; Thu, 7 Feb 2013 03:22:37 +0900 (JST) Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com [74.125.82.48]) by carbon.ruby-lang.org (Postfix) with ESMTP id 5759B3C229670 for ; Thu, 7 Feb 2013 03:22:36 +0900 (JST) Received: by mail-wg0-f48.google.com with SMTP id 16so1326520wgi.27 for ; Wed, 06 Feb 2013 10:22:34 -0800 (PST) Received: from [192.168.1.139] (188-142-112-225.FTTH.ispfabriek.nl. [188.142.112.225]) by mx.google.com with ESMTPS id n10sm4880581wia.0.2013.02.06.10.22.31 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 10:22:33 -0800 (PST) Delivered-To: ruby-core@ruby-lang.org Date: Thu, 7 Feb 2013 03:22:37 +0900 Posted: Wed, 06 Feb 2013 19:22:30 +0100 From: Yorick Peterse Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:51940] Re: [ruby-trunk - Feature #7792] Make symbols and strings the same thing To: ruby-core@ruby-lang.org Message-Id: <51129F66.9080107@gmail.com> In-Reply-To: <51128DA4.20706@gmail.com> References: <51126A63.4090302@gmail.com> <51126D47.3090902@gmail.com> <5112742F.5000403@gmail.com> <51128DA4.20706@gmail.com> X-ML-Name: ruby-core X-Mail-Count: 51940 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130109 Thunderbird/17.0.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=W3ZVYMLpH4UZ7Fp2FWQQPhEZ4HL69M1nwjF3G3eV88M=; b=Mgjbu4VF45Wxih8Vbtxtgm74U4lp6IusAx/qeJUK7rRxxAjhprAqJMCBCT54XUzFym UxRJ+vUuN+BZsHk6apOAXDtczmeBMUdpUpQPryVBQbcauKPfC2bKvj3NS5I2+e7IYe91 Y3l8bLEdxTtWqPldbGGfiNxK2luixrcRtZioCRk6fdc18m4QKnkxQMHjJH/YmsaSxcs/ LFyln0+Kq5ez8qCC+1M4WRXwFaKfbDlYMxS0auFPEQIjC+EUyyav6lE3Cgn9DQ0BUBLz PN3URykQJrHH5zJi1Y3ibAxCvWK7N2Njdujz28XMZruCNT/dleTQGlyFI94ClRqkSu8w M3/Q== X-Received: by 10.180.95.166 with SMTP id dl6mr6994250wib.9.1360174954784; Wed, 06 Feb 2013 10:22:34 -0800 (PST) X-Enigmail-Version: 1.5 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: > What I'm trying to say is that the main reason why symbols exist in > Ruby in the first place is performance from what I've been told. Correct, and your proposed changes would completely nullify those performance benefits (see below). > People reading some Ruby book will notice that it is not particularly > designed with performance in mind but it is designed mostly towards > programmer's happiness. If that is the case, then worrying about > bothered programmers makes sense to a language like Ruby in my > opinion. So basically what you're saying is "Ruby is written for happiness and not performance, lets make it even more slow!". I'd rather see a world where Ruby is both fast (enough) and easy to use instead of it being easy to use and slower than a sloth. Regarding the benchmarking information, you're missing a crucial aspect. While the numbers in the specific examples I gave both clearly show that the use of Strings is substantially slower. Yes, it's "only" 112 kb but the difference will keep growing and growing until you hit your memory limit. This is exactly one of the reasons Symbols exist: to make it easier and faster to use commonly re-used Strings. The best example of this are Hash keys. > This isn't possible when you're serializing/deserializing using some > library like JSON or any other. You don't control how hashes are > created by such libraries. Of course it is. Marshal allows you to store arbitrary Ruby objects (with the exception of a few such as Proc instances), in other cases you can re-create your objects based on the supplied Hash. If you do not like using raw Hashes the solution in my opinion is not to more or less re-write Ruby (and break everything that exists in the process) but instead solve this on your own application level. Using Hashie is one example but another one, one I consider far better, is to use your own classes. Consider the following: hash = {'id' => '123-abc-456', 'body' => 'hello'} if hash['id'] and !hash['id'].empty? puts "Processing message ID #{hash['id']}" end if hash['body'] and !hash['body'].empty? do_something(hash['body']) end This is not a flaw in your proposal in particular but it's one of the reasons why I'm not a big fan of using Hashes all over the place. If in this example the "id" key is suddenly changed to "ID" you now have at least 3 places where you have to modify your code and most likely other places further down the line. This can be solved by doing something as simple as the following: class Message attr_reader :id, :body def initialize(options) @id = options['id'] @body = options['body'] end def has_id? return @id && !@id.empty? end def has_body? return @body && !@body.empty? end end This allows you to write the following instead: message = Message.new({'id' => '123-abc-456', 'body' => 'hello'}) if message.has_id? puts "Processing message ID #{message.id}" end if has_body? do_something(message.body) end In this specific example it may seem a bit like an overkill but if that Hash gets used in a dozen places you can save yourself tremendous amounts of time by just wrapping a class around it. Yorick