Issue #16460 has been updated by zverok (Victor Shepelev).


>> 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).

Exactly my point. The Rubyists eye is trained to read `<identifier><space><something>` only two ways:
1. `<known keyword of a small list> вк <some statement depending on the keyword>`
2. `<method>(<something is argument to it>)`

You propose to introduce the "same" construct, which means something completely different, but due to our intutions, **in Ruby** `external_name internal_name:` reads as `external_name(internal_name:)`, which is misleading.

> 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:`

1. So, it should be read this way: `(within range):`, where both words are related to colon, with one being "title" and the second "explanation"? This, again unlike anything else in Ruby. It slightly reminds me of some documentation system links (yard, probably? with "Look also [FormalClassName that class]", or something like that... and I honestly never can remember which is which -- which is "link" and which is "title").
2. It works well for _some examples you constructed_, but there always can be counter-examples, like: I want to use `when:` argument, renaming it to `time` (becase `when` is a keyword), so... is it `time when:` or `when time:`?..
3. It is incredibly confusing for any parser (especially "rename as it is keyword" use-case) and syntax highlighter:`def foo(in time:` would be the only case where standalone `in<space><something>` should be parsed/hihglighted differently.

> A sort of middleground might be something like this:

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

This is also bad (by similar reasoning as above).

Some additional point: currently keyword args definitions reads this way: `method(arg1: ..., arg2: ...)` -- is how it would be called (e.g. in call-site we'll see the same structure `method(arg1: ..., arg2: ...)` -- and everything after the `:` is somewhat "how it is implemented" (for example, defaults calculation), which `=> put_to_this_variable` follows.

And one more consideration: imagine Ruby introduced one of those syntaxes in 2.8. And some rubyist who missed the announcement, comes to a "new" codebase, and how they would understand it?

```ruby
def foo(in: => time)
```
"...Ugh, what is it?.. Putting something into `time`? Ah, `in` is a keyword, they want to rename it. Got it. Hate it, but got it."
```ruby
def foo(in time: )
```
"...Ugh what?.. What?.. Is it a new keyword?.. Some kind of type hinting?.. No idea..."

(Pure speculations, obv.)

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

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