From: Austin Ziegler Date: 2019-11-05T14:23:16-05:00 Subject: [ruby-core:95706] Re: [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments --===============0478014274== Content-Type: multipart/alternative; boundary="0000000000002bd79605969e5ec9" --0000000000002bd79605969e5ec9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I am against this idea, as I=E2=80=99ve had more problems with `undefined` = in JavaScript than I have had with most other values, including null. I believe that I=E2=80=99ve needed to implement a =E2=80=9Cdefault sigil=E2= =80=9D object (like the Undefined object in DRY) maybe twice in the last 17 years and I=E2=80=99ve = 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 =3D Object.new class << sigil def @||(other) other end end -a On Mon, Nov 4, 2019 at 4:35 PM 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 =3D some_expression) > end > > def bar(default1 =3D some_expression) > foo default1 > end > > def foobar(default1 =3D some_expression) > bar default1 > end > ``` > > if you had "missing": > > ```ruby > def foo(default1 =3D some_expression) > end > > def bar(default1 =3D missing) > foo default1 > end > > def foobar(default1 =3D 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: > > --=20 Austin Ziegler =E2=80=A2 halostatue@gmail.com =E2=80=A2 austin@halostatue.c= a http://www.halostatue.ca/ =E2=80=A2 http://twitter.com/halostatue --0000000000002bd79605969e5ec9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I am against this idea, as I=E2=80=99ve had more problems = with `undefined` in JavaScript than I have had with most other values, incl= uding null. I believe that I=E2=80=99ve needed to implement a =E2=80=9Cdefa= ult sigil=E2=80=9D object (like the Undefined object in DRY) maybe twice in= the last 17 years and I=E2=80=99ve seen it in the wild in a couple of othe= r places.

This, to me, adds more _magic_ behaviour to Ru= by 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 ov= erride the `||` or `or` operators so that you could define an instance that= returns the other side:

sigil =3D Object.new
class << sigil
=C2=A0 def=C2=A0@||(other)
= =C2=A0 =C2=A0 other
=C2=A0 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).


>=C2=A0 Ruby having a single nil, instead of JavaScript's null and u= ndefined, is a net benefit, in my opinion.

undefined signals the absence of a value and makes possible composable defa= ult value design, where missing arguments can be forwarded and still trigge= r 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 n= obody 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 th= is 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 fo= rwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-8= 2467

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

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

def bar(default1 =3D some_expression)
=C2=A0 foo default1
end

def foobar(default1 =3D some_expression)
=C2=A0 bar default1
end
```

if you had "missing":

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

def bar(default1 =3D missing)
=C2=A0 foo default1
end

def foobar(default1 =3D missing)
=C2=A0 bar default1
end
```
missing passed as arg would be ignored (as if it wasn't passed at all)<= br> and you wouldn't have to repeat the default value expression in every m= ethod

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




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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe= >
<http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-core>


--
--0000000000002bd79605969e5ec9-- --===============0478014274== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============0478014274==--