ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:71353] [Ruby trunk - Feature #11660] [Open] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
@ 2015-11-05 20:36 ` alxtskrnk
  2019-11-01 19:02 ` [ruby-core:95641] [Ruby master Feature#11660] " bughitgithub
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: alxtskrnk @ 2015-11-05 20:36 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been reported by bug hit.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660

* Author: bug hit
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95641] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
  2015-11-05 20:36 ` [ruby-core:71353] [Ruby trunk - Feature #11660] [Open] a falsy value (similar to js undefined) that facilitates forwarding of default arguments alxtskrnk
@ 2019-11-01 19:02 ` bughitgithub
  2019-11-01 19:21 ` [ruby-core:95643] " merch-redmine
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: bughitgithub @ 2019-11-01 19:02 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by bughit (bug hit).


Compared to javascript default arg values are far less useful in ruby because of the lack of this forwarding capability.

This issue is 4 years old, can ruby core at least consider this?

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82429

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95643] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
  2015-11-05 20:36 ` [ruby-core:71353] [Ruby trunk - Feature #11660] [Open] a falsy value (similar to js undefined) that facilitates forwarding of default arguments alxtskrnk
  2019-11-01 19:02 ` [ruby-core:95641] [Ruby master Feature#11660] " bughitgithub
@ 2019-11-01 19:21 ` merch-redmine
  2019-11-01 21:33 ` [ruby-core:95644] " bughitgithub
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: merch-redmine @ 2019-11-01 19:21 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by jeremyevans0 (Jeremy Evans).


Other than arity, it seems like you would want to use the new argument forwarding syntax:

```ruby
def foo(default1 = some_expression)
end

def bar(...)
  foo(...)
end

def foobar(...)
  bar(...)
end 
```

The major issue with adding this support is what the value of this is:

```ruby
def foobar(default1 = missing)
  default1
end 
```

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82431

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95644] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-11-01 19:21 ` [ruby-core:95643] " merch-redmine
@ 2019-11-01 21:33 ` bughitgithub
  2019-11-01 21:55 ` [ruby-core:95645] " merch-redmine
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: bughitgithub @ 2019-11-01 21:33 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by bughit (bug hit).


> Other than arity, it seems like you would want to use the new argument forwarding syntax

I didn't know about new syntax, is that in 2.7? However, I don't think that's general enough. In javascript you can forward individual arguments to an arbitrary depth and the default value is computed once at the end.

```js

function f1(a = defaultValueExpression) {
}

function f2({b = 1, c} = {}) {
  f1(c);
}

function f3(d, e) {
  f2({b: d, c: e});
}

f3(1)

// or

f3(1, undefined)


```

the missing/undefined second arg to f3 invocation flows all the way down to f1 where it triggers default value computation

You can't do this in ruby, to accomplish the equivalent you'd have to stop using intended default value expressions, forward nils, and then compute the default value in the body of the method. 

```ruby

def f1(a = nil)
  a = default_value_expression if a.nil?
end

def f2(b: 1, c: nil)
  f1(c)
end

def f3(d, e = nil)
  f2(b: d, c: e)
end

f3(1)

```

So in ruby the default value feature is close to being demoware. In practice, when composing methods, you end up reverting to the above. 

> The major issue with adding this support is what the value of this is

The value would be `missing`. Adding something like `missing` to the language would need to be coupled with a null coalescing operator which would cover both nil and missing (but not false). Something like `??` and `??=`





----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82432

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95645] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-11-01 21:33 ` [ruby-core:95644] " bughitgithub
@ 2019-11-01 21:55 ` merch-redmine
  2019-11-01 23:55 ` [ruby-core:95648] " bughitgithub
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: merch-redmine @ 2019-11-01 21:55 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by jeremyevans0 (Jeremy Evans).


bughit (bug hit) wrote:
> The value would be `missing`. Adding something like `missing` to the language would need to be coupled with a null coalescing operator which would cover both nil and missing (but not false). Something like `??` and `??=`

Adding a new keyword and operator seems like a high cost for at best a very minor benefit, in my opinion.  I'm definitely against adding this.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82433

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95648] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-11-01 21:55 ` [ruby-core:95645] " merch-redmine
@ 2019-11-01 23:55 ` bughitgithub
  2019-11-02  0:32 ` [ruby-core:95649] " XrXr
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: bughitgithub @ 2019-11-01 23:55 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by bughit (bug hit).


It's conceivable that it can be done without a keyword, there are other way to refer to special values.

However what do you have against a null coalescing operator? It's needed regardless of this issue, || and ||= are inadequate because of false.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82436

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95649] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2019-11-01 23:55 ` [ruby-core:95648] " bughitgithub
@ 2019-11-02  0:32 ` XrXr
  2019-11-02 10:06 ` [ruby-core:95652] " fg
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: XrXr @ 2019-11-02  0:32 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by alanwu (Alan Wu).


Since the beginning of time (correct me if I'm wrong), the two falsy values in Ruby has been `false` and `nil`, period.
Adding another falsy value is a big change.

> the missing/undefined second arg to f3 invocation flows all the way down to f1 where it triggers default value computation
> You can't do this in ruby,

You can do it if all the methods in the chain use splat. In 2.7 `...` also works:

```ruby
def f3(foo = 500, bar)
  p [foo, bar]
end

def f2(*args)
  f3(*args)
end

def f1(*args)
  f2(*args)
end

f1(:bar) # [500, :bar]
```
https://wandbox.org/permlink/3xAq9B2wQk8odafG

Default args have been a feature for a long time, the fact there hasn't been
proposal similar to yours suggests to me that it's not a feature in high
demand.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82437

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95652] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2019-11-02  0:32 ` [ruby-core:95649] " XrXr
@ 2019-11-02 10:06 ` fg
  2019-11-03 18:57 ` [ruby-core:95661] " bughitgithub
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: fg @ 2019-11-02 10:06 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by decuplet (Nikita Shilnikov).


For this purpose, I built a [special value](https://github.com/dry-rb/dry-core/blob/99e4035148af729298430aefe85b4c93cb318195/lib/dry/core/constants.rb#L41) a while ago. It has been working fine all this time. I don't think there's a need in adding such special-cased value to the language. It would only slightly improve the experience over a hand-crafted ten-lines-of-code solution. The whole story of passing arguments in Ruby is already complicated enough.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82440

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95661] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2019-11-02 10:06 ` [ruby-core:95652] " fg
@ 2019-11-03 18:57 ` bughitgithub
  2019-11-04 10:24 ` [ruby-core:95664] " fg
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: bughitgithub @ 2019-11-03 18:57 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by bughit (bug hit).


> For this purpose I built a special value a while ago

What purpose? Surely you understand that your special value, having no compiler support, does not trigger default value computations.

You are making my point. Your Undefined is not a real, intended default value, but a signal to compute the real default value in the body of the method after an explicit check for this signal. 

This under-baked design of the default value feature is the point of this bug.




----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82450

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95664] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2019-11-03 18:57 ` [ruby-core:95661] " bughitgithub
@ 2019-11-04 10:24 ` fg
  2019-11-04 15:22 ` [ruby-core:95668] " daniel
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: fg @ 2019-11-04 10:24 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by decuplet (Nikita Shilnikov).


The "penalty" I pay for this is one line of code like `period = Undefined.default(period, :day)`. Given this doesn't occur very often I don't see how "compiler support" would be beneficial.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82451

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95668] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2019-11-04 10:24 ` [ruby-core:95664] " fg
@ 2019-11-04 15:22 ` daniel
  2019-11-04 17:00 ` [ruby-core:95671] " bughitgithub
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: daniel @ 2019-11-04 15:22 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by Dan0042 (Daniel DeLorme).


alanwu (Alan Wu) wrote:
> Since the beginning of time (correct me if I'm wrong), the two falsy values in Ruby has been `false` and `nil`, period.
> Adding another falsy value is a big change.

I Agree. Not saying there's no benefit, but this is too big a change for too small a benefit. Usually `nil` will play the role of the undefined value, so it might be nice if a method definition allowed something like `def foo(v ||= 42)`. But nowadays we have keyword arguments which do exactly what is needed in this case.

```ruby
def f2(x: 2)
  x
end

def f1(y:1, **kw)
  y + f2(**kw)
end

f1(y: 3) #=> 5
```

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82454

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95671] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2019-11-04 15:22 ` [ruby-core:95668] " daniel
@ 2019-11-04 17:00 ` bughitgithub
  2019-11-04 17:42 ` [ruby-core:95673] " merch-redmine
  2019-11-04 21:35 ` [ruby-core:95680] " bughitgithub
  13 siblings, 0 replies; 15+ messages in thread
From: bughitgithub @ 2019-11-04 17:00 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by bughit (bug hit).


> The "penalty" I pay for this is one line of code

The penalty the language pays is it has a demoware, checklist item, default value feature, where in any non-trivial scenario you have to produce the default value twice, first the intermediate default value through the default value expression, then the real default value in the body. You are not doing ruby any favors by defending this "design".

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82459

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95673] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2019-11-04 17:00 ` [ruby-core:95671] " bughitgithub
@ 2019-11-04 17:42 ` merch-redmine
  2019-11-04 21:35 ` [ruby-core:95680] " bughitgithub
  13 siblings, 0 replies; 15+ messages in thread
From: merch-redmine @ 2019-11-04 17:42 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by jeremyevans0 (Jeremy Evans).


bughit (bug hit) wrote:
> The penalty the language pays is it has a demoware, checklist item, default value feature, where in any non-trivial scenario you have to produce the default value twice, first the intermediate default value through the default value expression, then the real default value in the body.

There are many non-trivial scenarios where you don't need to do that (or we can have a no-true-Scotsman argument about the definition of non-trivial scenario).  Most method calls do not involve calling methods that delegate arguments to another method where both methods have the same optional argument with the same default value.  In the cases where that happens, the general practice is just to duplicate the default value in both methods, which is not usually an issue as default values are usually simple values or method calls.

The only time you really want to have the "real default value" in the body is in fairly complex cases, and in those cases, the default argument values are usually set to `nil`.  This is easy to understand and has worked well for Ruby for a long time.  Ruby having a single `nil`, instead of JavaScript's `null` and `undefined`, is a net benefit, in my opinion.

> You are not doing ruby any favors by defending this "design".

You are not doing Ruby any favors by making a mountain out of a molehill.  The popularity of an idea is not always a proxy to its merit, but if nobody else thinks the benefits of a proposal exceed the costs, maybe it isn't worth implementing.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82461

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95680] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
       [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2019-11-04 17:42 ` [ruby-core:95673] " merch-redmine
@ 2019-11-04 21:35 ` bughitgithub
  2019-11-05 19:23   ` [ruby-core:95706] " Austin Ziegler
  13 siblings, 1 reply; 15+ messages in thread
From: bughitgithub @ 2019-11-04 21:35 UTC (permalink / raw)
  To: ruby-core

Issue #11660 has been updated by bughit (bug hit).


>  Ruby having a single nil, instead of JavaScript's null and undefined, is a net benefit, in my opinion.

undefined signals the absence of a value and makes possible composable default value design, where missing arguments can be forwarded and still trigger default value computation, which is a clear win for javascript.

> The popularity of an idea is not always a proxy to its merit, but if nobody else thinks the benefits of a proposal exceed the costs, maybe it isn't worth implementing.

Ok got it. Popularity does not always equal merit, but often it does and this must be one of those times, because of course it has no merit and it's unpopular. Ergo ipso facto, it has no merit.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82467

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:95706] Re: [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
  2019-11-04 21:35 ` [ruby-core:95680] " bughitgithub
@ 2019-11-05 19:23   ` Austin Ziegler
  0 siblings, 0 replies; 15+ messages in thread
From: Austin Ziegler @ 2019-11-05 19:23 UTC (permalink / raw)
  To: Ruby developers


[-- Attachment #1.1: Type: text/plain, Size: 3063 bytes --]

I am against this idea, as I’ve had more problems with `undefined` in
JavaScript than I have had with most other values, including null. I
believe that I’ve needed to implement a “default sigil” object (like the
Undefined object in DRY) maybe twice in the last 17 years and I’ve seen it
in the wild in a couple of other places.

This, to me, adds more _magic_ behaviour to Ruby that is somewhat
unexplainable, whereas using a `missing` sigil object (e.g., Undefined)
requires explicit handling and is fairly clear.

This _could_ be fixed in some ways if it were possible to override the `||`
or `or` operators so that you could define an instance that returns the
other side:

sigil = Object.new
class << sigil
  def @||(other)
    other
  end
end

-a

On Mon, Nov 4, 2019 at 4:35 PM <bughitgithub@gmail.com> wrote:

> Issue #11660 has been updated by bughit (bug hit).
>
>
> >  Ruby having a single nil, instead of JavaScript's null and undefined,
> is a net benefit, in my opinion.
>
> undefined signals the absence of a value and makes possible composable
> default value design, where missing arguments can be forwarded and still
> trigger default value computation, which is a clear win for javascript.
>
> > The popularity of an idea is not always a proxy to its merit, but if
> nobody else thinks the benefits of a proposal exceed the costs, maybe it
> isn't worth implementing.
>
> Ok got it. Popularity does not always equal merit, but often it does and
> this must be one of those times, because of course it has no merit and it's
> unpopular. Ergo ipso facto, it has no merit.
>
> ----------------------------------------
> Feature #11660: a falsy value (similar to js undefined) that facilitates
> forwarding of default arguments
> https://bugs.ruby-lang.org/issues/11660#change-82467
>
> * Author: bughit (bug hit)
> * Status: Open
> * Priority: Normal
> * Assignee:
> * Target version:
> ----------------------------------------
> I'll call it "missing" here.  Consider the following scenario:
>
> ```ruby
> def foo(default1 = some_expression)
> end
>
> def bar(default1 = some_expression)
>   foo default1
> end
>
> def foobar(default1 = some_expression)
>   bar default1
> end
> ```
>
> if you had "missing":
>
> ```ruby
> def foo(default1 = some_expression)
> end
>
> def bar(default1 = missing)
>   foo default1
> end
>
> def foobar(default1 = missing)
>   bar default1
> end
> ```
> missing passed as arg would be ignored (as if it wasn't passed at all)
> and you wouldn't have to repeat the default value expression in every
> method
>
> I believe that's how undefined works in js6 with respect to default args
>
>
>
>
> --
> 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>
>


-- 
Austin Ziegler • halostatue@gmail.com • austin@halostatue.ca
http://www.halostatue.ca/http://twitter.com/halostatue

[-- Attachment #1.2: Type: text/html, Size: 4375 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-11-05 19:23 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-11660.20151105203635@ruby-lang.org>
2015-11-05 20:36 ` [ruby-core:71353] [Ruby trunk - Feature #11660] [Open] a falsy value (similar to js undefined) that facilitates forwarding of default arguments alxtskrnk
2019-11-01 19:02 ` [ruby-core:95641] [Ruby master Feature#11660] " bughitgithub
2019-11-01 19:21 ` [ruby-core:95643] " merch-redmine
2019-11-01 21:33 ` [ruby-core:95644] " bughitgithub
2019-11-01 21:55 ` [ruby-core:95645] " merch-redmine
2019-11-01 23:55 ` [ruby-core:95648] " bughitgithub
2019-11-02  0:32 ` [ruby-core:95649] " XrXr
2019-11-02 10:06 ` [ruby-core:95652] " fg
2019-11-03 18:57 ` [ruby-core:95661] " bughitgithub
2019-11-04 10:24 ` [ruby-core:95664] " fg
2019-11-04 15:22 ` [ruby-core:95668] " daniel
2019-11-04 17:00 ` [ruby-core:95671] " bughitgithub
2019-11-04 17:42 ` [ruby-core:95673] " merch-redmine
2019-11-04 21:35 ` [ruby-core:95680] " bughitgithub
2019-11-05 19:23   ` [ruby-core:95706] " Austin Ziegler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).