Issue #16460 has been updated by harrisonb (Harrison Bachrach).


zverok (Victor Shepelev) wrote:

> It also means _exactly_ "...and put in this variable" in this cases:
> 
> * `rescue Exception => e` (always)
> * `key: pattern => variable` (2.7's pattern matching)

I stand corrected! That is a compelling refutation of my point.

> * 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)`)

I suppose this is a thoroughly different syntax (this doesn't really bother me, but perhaps it should).

> * 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`"

The correct order makes grammatical sense for the common use-cases of `preposition non-preposition`:

* `to destination:` vs. `destination to:`
* `with klass:` vs. `klass with:`
* `within range:` vs. `range within:`


---
A sort of middleground might be something like this:

`def move(from => source:, to => destination:)`

----------------------------------------
Feature #16460: External names for keyword parameters in method definitions
https://bugs.ruby-lang.org/issues/16460#change-83471

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>