From: zverok.offline@... Date: 2019-12-28T08:59:22+00:00 Subject: [ruby-core:96542] [Ruby master Feature#16460] External names for keyword parameters in method definitions Issue #16460 has been updated by zverok (Victor Shepelev). > it reverses the common meaning of `=>` in Ruby of `key => value`. But what is "common" meaning? `key => value` just means "key corresponds to value" (which you also can read "parameter name corresponds to (=>) local variable"). It also means _exactly_ "...and put in this variable" in this cases: * `rescue Exception => e` (always) * `key: pattern => variable` (2.7's pattern matching) And generally, one may theorize that `=> foo` can be read like "put someting into foo". With `foo bar:` syntax there are two problems: * It is unlike _anything_ that exists in Ruby (I can't remember a thing where two names separated by space would be a standalone syntax and not just a shortcut, say `puts x` === `puts(x)`) * For me, it is totally un-mnemonic: is it `external_name internal_name:` or `internal_name external_name:`? How one should remember? How many time one will confuse it and swear "why it does not works like tutorial says???" At least `foo: => bar` _can_ be taught as "name some thing `foo:` (its _key_ is `foo:`) and put it _into_ (=>) `bar`" ---------------------------------------- Feature #16460: External names for keyword parameters in method definitions https://bugs.ruby-lang.org/issues/16460#change-83470 * Author: harrisonb (Harrison Bachrach) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Hello! This is my first time filing an issue and I was unable to find anything similar. I apologize if one already exists. In other languages (such as JavaScript, Swift, and Crystal), it is possible to have two names for a given keyword argument: one that is used in method invocation, and one used in the method definition. Here is an example from Crystal (which has syntax very similar to Ruby): ```crystal def increment(value, by amount) value + amount end increment(value: 5, by: 10) ``` This helps create more readable method invocations and definitions. It would be especially helpful in Ruby as the language lacks a destructuring syntax for hashes/keyword args. This is unlike JavaScript, where you can do something like ```javascript const { nameOfOneProperty: newNameForTheProperty, nameOfAnotherProperty: newNameForTheOtherProperty } = foo; ``` I'm thinking that such a change would pair nicely with the new 3.0 keyword argument changes. A suggested syntax might be ```ruby def name(external_name internal_name:) # ... end -- https://bugs.ruby-lang.org/ Unsubscribe: