From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.2 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id B7C141F453 for ; Fri, 19 Oct 2018 14:13:33 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 65B73121042; Fri, 19 Oct 2018 23:13:30 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 1E16A120D8B for ; Fri, 19 Oct 2018 23:13:27 +0900 (JST) Received: by filter0072p3las1.sendgrid.net with SMTP id filter0072p3las1-13953-5BC9E683-23 2018-10-19 14:13:23.383353129 +0000 UTC m=+60432.100063399 Received: from herokuapp.com (ec2-50-19-154-248.compute-1.amazonaws.com [50.19.154.248]) by ismtpd0025p1mdw1.sendgrid.net (SG) with ESMTP id VBKqDJZOSouIK95-3Xek3g for ; Fri, 19 Oct 2018 14:13:23.189 +0000 (UTC) Date: Fri, 19 Oct 2018 14:13:24 +0000 (UTC) From: shevegen@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 64861 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15236 X-Redmine-Issue-Author: ignatiusreza X-Redmine-Sender: shevegen X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7vU2F3B8Mtd16OugwxS7jF9w4X9yfIPQyPai s/zlINa++C/x+ZDDGC5FfoiZpZvZ0FmFNIFczZsUczR1q4LvyYvN5p9owO290L9XCiZXH6bu28gctq qoxg+O/DU5K8YloADVl5Vx/JB2l+fcwZ97z0RUt325oOwDk+bD0GU1sk5w== X-ML-Name: ruby-core X-Mail-Count: 89475 Subject: [ruby-core:89475] [Ruby trunk Feature#15236] add support for hash shorthand X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15236 has been updated by shevegen (Robert A. Heiler). Hmm. It's hard for me to say whether I am in favour of this suggestion or whether I am not. I think this link may help a bit in regards to JavaScript, even though JavaScript is not Ruby; neither is the syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer Old JavaScript variant: var o = {}; var o = {a: 'foo', b: 42, c: {}}; versus New JavaScript variant: var a = 'foo', b = 42, c = {}; var o = {a, b, c}; I understand the second part being more convenient and more concise. I am not really sure whether it makes sense for ruby to adopt this, though. The part where "omission means something more", is sometimes confusing. I myself got used to be able to omit {} in a method definition, such as your example: m(a, b, c: c) which I think would be this: m(a, b, { c: c }) I also use the somewhat new Hash syntax in ruby a lot, like: foo: :bar versus the old variant (but still the "real" variant) :foo => :bar I am not entirely sure about the new omission-meaning-infinity in ranges ( 1 .. ) either, or { a } meaning { a: a } like in the proposal here, where a is a variable that must exist already, if { a } is to work. This also reminds me a bit about the shortcut suggestion for initializing instance variables within the method-argument, rather than the body of the method at hand (usually "def initialize"). I don't really have a definite pro or con view but I think it should be thought through for some time either way. While experienced ruby developers have it easy learning new syntax parts, newcomers may have to gradually learn more and more syntax parts, which may not be ideal for them, even if the new syntax may be shorter. Or where the syntax allows us to do more with {}, rather than with Hash.new - that should also be considered to evaluate all trade-offs and advantages/disadvantages. If you would like to, you could add your suggestion to any upcoming developer meeting where you could get some opinions from the ruby core team and of course matz (which would be at https://bugs.ruby-lang.org/issues/15229 for the next one in November 2018; or perhaps for a later one in January 2019 since I assume most energy of the team may go into the upcoming x-mas release of ruby :) ). ---------------------------------------- Feature #15236: add support for hash shorthand https://bugs.ruby-lang.org/issues/15236#change-74516 * Author: ignatiusreza (Ignatius Reza Lesmana) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- PR in github: https://github.com/ruby/ruby/pull/1990 inspired by javascript support for object literal shorthand notation `{ a }`, which will be expanded into `{ a: a }`.. to avoid ambiguity, this shorthand is only supported when hash is defined with `{ }` notation.. in other situation where the brackets is optional, e.g. function call, we still need to write it in full (`m(a : a)` instead of `m(a)`, or `m(a, b, c: c)` instead of `m(a, b, c)`.. -- https://bugs.ruby-lang.org/