From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, MIME_HTML_MOSTLY,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 07B3420248 for ; Tue, 26 Mar 2019 14:49:22 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 80FF3121625; Tue, 26 Mar 2019 23:49:16 +0900 (JST) Received: from mail-ua1-f65.google.com (mail-ua1-f65.google.com [209.85.222.65]) by neon.ruby-lang.org (Postfix) with ESMTPS id EC9CC121625 for ; Tue, 26 Mar 2019 23:49:09 +0900 (JST) Received: by mail-ua1-f65.google.com with SMTP id b8so4378795uaq.7 for ; Tue, 26 Mar 2019 07:49:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=s+mg3fAyioEJKa/vEP2hz9BpTutBrnMXlDFjQHtJ6mg=; b=mZ8gyCIhO6E3raoHDzXVm0hds75DInQTYLVDlzhK6P4uvAaOd1uYidvRxu4zMcc1z6 bDnevE09BRoj9l1ADyjUquOBzpFaps7QR2+Cvr11hu78HkDnZDQjQRwiFnPWFJxOmNHh XdbhvKn9O6p6qSJxwJy3Q3mPWz+vSJRYBNJIcGhu6eaDh1uE7lIg6+OeWEC6qjL7Pluq VUXxJSEYgmuGUFFniiHTLasjx/XlCqDOzjI9OUM9wsj1fpdoh1wSRcOy2Exjts4W1bR9 XxQrSMNuqNiwSXT3/1vvGuNOiVRlMHSHCH7oRZ9pwdnlCAd7UMcLqPwJggmW0qI1u2sP Pupw== X-Gm-Message-State: APjAAAWYjbseIMAukHgP6e3cl4hUayspC8FkZ42RTo1cyp4y+ou3tSoZ akQ7RAZQ+KnNFrcmeGp0dXaYdyLI+hoPvdkn5F3kSQ== X-Google-Smtp-Source: APXvYqykF0Cez64sMfvEUiY3dDvAzmpxss7XDwL7U9TsuWaHOKs1hz07fqhhYPIzF9qEZwjtVrDmaiJaE1iQXlOC+/s= X-Received: by 2002:ab0:2a53:: with SMTP id p19mr1146130uar.100.1553611749390; Tue, 26 Mar 2019 07:49:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Austin Ziegler Date: Tue, 26 Mar 2019 10:48:52 -0400 Message-ID: To: Ruby developers X-ML-Name: ruby-core X-Mail-Count: 91996 Subject: [ruby-core:91996] Re: [Ruby trunk Misc#15723] Reconsider numbered parameters X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============0941094816==" Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Content-Transfer-Encoding: 7bit --===============0941094816== Content-Type: multipart/alternative; boundary="00000000000070ffce0585006cb4" --00000000000070ffce0585006cb4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I define globals all the time for short scripts. It=E2=80=99s rare that I d= efine `$it`, but I have done so in the past. On Tue, Mar 26, 2019 at 3:57 AM wrote: > Issue #15723 has been updated by bozhidar (Bozhidar Batsov). > > > > $it can already be defined, so this is not backwards compatible. > > It can, but that's extremely unlikely, so I think the impact to backwards > compatibility would be negligible. I've almost never seen anyone define > globals themselves. I don't think it's wise to eliminate some possibiliti= es > simply because they *might* cause minimal problems. > > Btw, using `%1`, `%2`, `%3` is fine, right? How do people feel about that > one in general. I'm kind of used to it, because that's how Clojure does i= t, > but I'm curious if it feels very weird in general. > > > If it will be multiple params @1, @2, etc. Can we also have @ aliasing > @1? I think it's going to be a common use case to just have the one param= . > > I think that would look extra weird, but in general it's a good idea > (especially if the special var had some meaningful name). > > ---------------------------------------- > Misc #15723: Reconsider numbered parameters > https://bugs.ruby-lang.org/issues/15723#change-77321 > > * Author: sos4nt (Stefan Sch=C3=BC=C3=9Fler) > * Status: Feedback > * Priority: Normal > * Assignee: > ---------------------------------------- > I just learned that *numbered parameters* have been merged into Ruby > 2.7.0dev. > > For readers not familiar with this feature: it allows you to reference > block arguments solely by their *index*, e.g. > > ```ruby > [1, 2, 3].each { |i| puts i } > > # can become > > [1, 2, 3].each { puts @1 } > ``` > > I have an issue with this new feature: I think **it encourages sloppy > programming** and results in **hard to read code**. > > --- > > The [original proposal](https://bugs.ruby-lang.org/issues/4475) was to > include a special variable (or keyword) with a **readable name**, somethi= ng > like: > > ```ruby > [1, 2, 3].each { puts it } > > # or > > [1, 2, 3].each { puts this } > ``` > > Granted, that looks quite lovely and it actually speaks to me =E2=80=93 I= can > *understand* the code. And it fits Ruby: (quoting the website) > > > [Ruby] has an elegant syntax that is natural to read and easy to write. > > But the proposed `it` / `this` has limited application. It's only useful > when dealing with a single argument. You can't have multiple `it`-s or > `this`-es. That's why `@1`, `@2`, `@3` etc. were chosen instead. > > However, limiting the usefulness to a single argument isn't bad at at. In > fact, a single argument seem to be the limit of what makes sense: > ``` > h =3D Hash.new { |hash, key| hash[key] =3D "Go Fish: #{key}" } > > # vs > > h =3D Hash.new { @1[@2] =3D "Go Fish: #{@2}" } > ``` > Who wants to read the latter? That looks like an archaic bash program (no > offense). We already discourage Perl style `$`-references: (from [The Rub= y > Style Guide]( > https://github.com/rubocop-hq/ruby-style-guide#no-perl-regexp-last-matche= rs > )) > > > Don't use the cryptic Perl-legacy variables denoting last regexp group > matches (`$1`, `$2`, etc). Use `Regexp.last_match(n)` instead. > > I don't see how our code can benefit from adding `@1` and `@2`. > > Naming a parameter isn't useless =E2=80=93 it gives context. With more th= an one > parameter, naming is crucial. And yes, naming is hard. But avoiding prope= r > naming by using indices is the wrong way. > > So please reconsider numbered parameters. > > Use a readable named variable (or keyword) to refer to the first argument > or ditch the feature entirely. > > > > -- > 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 --00000000000070ffce0585006cb4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I define globals all the time for short scripts. It=E2=80= =99s rare that I define `$it`, but I have done so in the past.

On Tue, Mar 2= 6, 2019 at 3:57 AM <bozhidar@bats= ov.com> wrote:
Issue #15723 has been updat= ed by bozhidar (Bozhidar Batsov).


> $it can already be defined, so this is not backwards compatible.

It can, but that's extremely unlikely, so I think the impact to backwar= ds compatibility would be negligible. I've almost never seen anyone def= ine globals themselves. I don't think it's wise to eliminate some p= ossibilities simply because they *might* cause minimal problems.

Btw, using `%1`, `%2`, `%3` is fine, right? How do people feel about that o= ne in general. I'm kind of used to it, because that's how Clojure d= oes it, but I'm curious if it feels very weird in general.

> If it will be multiple params @1, @2, etc. Can we also have @ aliasing= @1? I think it's going to be a common use case to just have the one pa= ram.

I think that would look extra weird, but in general it's a good idea (e= specially if the special var had some meaningful name).

----------------------------------------
Misc #15723: Reconsider numbered parameters
https://bugs.ruby-lang.org/issues/15723#change-7= 7321

* Author: sos4nt (Stefan Sch=C3=BC=C3=9Fler)
* Status: Feedback
* Priority: Normal
* Assignee:
----------------------------------------
I just learned that *numbered parameters* have been merged into Ruby 2.7.0d= ev.

For readers not familiar with this feature: it allows you to reference bloc= k arguments solely by their *index*, e.g.

```ruby
[1, 2, 3].each { |i| puts i }

# can become

[1, 2, 3].each { puts @1 }
```

I have an issue with this new feature: I think **it encourages sloppy progr= amming** and results in **hard to read code**.

---

The [original proposal](https://bugs.ruby-lang.org/issues/4475= ) was to include a special variable (or keyword) with a **readable name= **, something like:

```ruby
[1, 2, 3].each { puts it }

# or

[1, 2, 3].each { puts this }
```

Granted, that looks quite lovely and it actually speaks to me =E2=80=93 I c= an *understand* the code. And it fits Ruby: (quoting the website)

> [Ruby] has an elegant syntax that is natural to read and easy to write= .

But the proposed `it` / `this` has limited application. It's only usefu= l when dealing with a single argument. You can't have multiple `it`-s o= r `this`-es. That's why `@1`, `@2`, `@3` etc. were chosen instead.

However, limiting the usefulness to a single argument isn't bad at at. = In fact, a single argument seem to be the limit of what makes sense:
```
h =3D Hash.new { |hash, key| hash[key] =3D "Go Fish: #{key}" }
# vs

h =3D Hash.new { @1[@2] =3D "Go Fish: #{@2}" }
```
Who wants to read the latter? That looks like an archaic bash program (no o= ffense). We already discourage Perl style `$`-references: (from [The Ruby S= tyle Guide](https://githu= b.com/rubocop-hq/ruby-style-guide#no-perl-regexp-last-matchers))

> Don't use the cryptic Perl-legacy variables denoting last regexp g= roup matches (`$1`, `$2`, etc). Use `Regexp.last_match(n)` instead.

I don't see how our code can benefit from adding `@1` and `@2`.

Naming a parameter isn't useless =E2=80=93 it gives context. With more = than one parameter, naming is crucial. And yes, naming is hard. But avoidin= g proper naming by using indices is the wrong way.

So please reconsider numbered parameters.

Use a readable named variable (or keyword) to refer to the first argument o= r ditch the feature entirely.



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


--
--00000000000070ffce0585006cb4-- --===============0941094816== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============0941094816==--