From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,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.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 11B0C1F453 for ; Mon, 29 Apr 2019 17:56:45 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 8EC6C120998; Tue, 30 Apr 2019 02:56:39 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4C5F9120946 for ; Tue, 30 Apr 2019 02:56:37 +0900 (JST) Received: by filter0045p3iad2.sendgrid.net with SMTP id filter0045p3iad2-12045-5CC73AB7-9 2019-04-29 17:56:07.237677101 +0000 UTC m=+336878.254547081 Received: from herokuapp.com (unknown [54.161.168.50]) by ismtpd0015p1iad1.sendgrid.net (SG) with ESMTP id vnGSwMxNSu2bG2WFPSg7ww for ; Mon, 29 Apr 2019 17:56:07.090 +0000 (UTC) Date: Mon, 29 Apr 2019 17:56:07 +0000 (UTC) From: tleish@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 67964 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15236 X-Redmine-Issue-Author: ignatiusreza X-Redmine-Sender: tleish 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: =?us-ascii?Q?1Ogw2e3M8iuH+ElzMoOQbR5VA30pP1ppaX6vMLJXdUan6jsNZhS5g7WgFO5omG?= =?us-ascii?Q?AdYQ7XtjM4iqyQPUZ+Mmk6MU4K6hWhy06F75Bbv?= =?us-ascii?Q?Qi1BKT9A6J6ZWkPdtpZuWmFRiSvhZSu+1zzBGiq?= =?us-ascii?Q?REASNIdex9W83TAqGL0b7YVzc8Rfu7Nn0uphsOf?= =?us-ascii?Q?6Ue15EGkXcwVjph8tdFbr1YTeva3uQNpuOA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92481 Subject: [ruby-core:92481] [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 tleish (Tony Fenleish). +1 I also vote for this option for both hashes and named params. After using Es6 and going back to Ruby, the ruby way felt clunky to me. There are multiple reasons why this would be advantageous. ## Readability: I like the named params that was added to Ruby. It allows flexibility in the order of the params. but often struggle in convincing myself to use them because of readability. Code examples often show the following: ```ruby my_hash = {name: 'joe', age: 8} # or my_method(name: 'Joe', age: 8) ``` But in the real world, the values are usually stored in other variables and 95% of the time the code looks like this: ```ruby my_hash = {name: name, age: age} # or my_method(name: name, age: age) ``` The above code does not ready well with it's redundant words. With the change suggested, it reads so much better: ```ruby my_hash = {name, age} # or my_method(name, age) ``` If the variable is different than the param name, then it easily communicates that: ```ruby my_hash = {name, age: calculate_age} # or my_method(name, age: calculate_age) ``` ## Refactoring If a method is implemented without keyword arguments: ```ruby def my_method(name, age); end my_method(name, age) ``` And then later it is decided to refactor using ruby keywords ```ruby def my_method(name:, age:, address: nil); end ``` This of course is a breaking change. All locations which use this method now need to be updated to use the new convention. ```ruby my_method(name: name, age: age) ``` However, for instances where the method was was implemented using variables of the same as the parameters (which often they are), then the change is non-breaking. ```ruby my_method(name, age) # no change required ``` ---------------------------------------- Feature #15236: add support for hash shorthand https://bugs.ruby-lang.org/issues/15236#change-77827 * 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/