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=-2.6 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no 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 24C171F4B4 for ; Fri, 2 Apr 2021 05:42:31 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E7E701209C4; Fri, 2 Apr 2021 14:41:27 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 9BA5E120988 for ; Fri, 2 Apr 2021 14:41:25 +0900 (JST) Received: by filterdrecv-p3iad2-7d7c446bd4-z6wz8 with SMTP id filterdrecv-p3iad2-7d7c446bd4-z6wz8-19-6066AEBC-6 2021-04-02 05:42:20.158144124 +0000 UTC m=+817759.981323218 Received: from herokuapp.com (unknown) by ismtpd0142p1iad2.sendgrid.net (SG) with ESMTP id g2sML8vuSwabPCY4KREw1Q for ; Fri, 02 Apr 2021 05:42:20.142 +0000 (UTC) Date: Fri, 02 Apr 2021 05:42:20 +0000 (UTC) From: sawadatsuyoshi@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79209 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17773 X-Redmine-Issue-Author: sawa X-Redmine-Sender: sawa X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?jFXA8Rt481sXUUIO9tYW1AJlMOZdNdlSw=2F5TfLCefGt15bkaE7uPNGD3=2FkMTmc?= =?us-ascii?Q?pKC0UxrgJKrRepEVKhyTWIzBEwtWCuwPCVFirrV?= =?us-ascii?Q?V2gRt1Kgx+g0WG3KCo3scy+RSnv4FXNcA96yWsu?= =?us-ascii?Q?oX3V4KTM=2FuvlJCJ6Jf91ZHg67w9AdztgZaLJzRq?= =?us-ascii?Q?t2ZnVeQPZn2hxK0rg4c5=2FwZWrw0kh6HKtcVDClE?= =?us-ascii?Q?Sjf5Iq1tn3+vCIQ8g=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103166 Subject: [ruby-core:103166] [Ruby master Feature#17773] Alias `Numeric#zero?` and `Float#zero?` as `Numeric#empty?` and `Float#empty?` 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: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17773 has been updated by sawa (Tsuyoshi Sawada). jeremyevans0 (Jeremy Evans) wrote in #note-2: > If you are checking for user input, aliasing `zero?` to `empty?` seems wrong, as `0` is a valid non-empty user input. I do not understand what you exactly mean by 0 is valid. But presumably, if 0 is valid in whatever sense you have in mind, then empty string is valid as well in the same sense. On the other hand, in some contexts, 0 is not valid, say, for a transfer amount in a bank transfer page, just as an empty string is not valid, say, in a required user's name field in a registration form. On top of that, in the first place, the distinction in question is not valid vs. invalid. That is irrelevant. It is about explicit input vs. default. > [I}f you care whether a user input was empty, you should check whether a user input string is empty before converting it to a number, instead of after. As for numeric fields, I am discussing cases where the default is `0` and the user input (via `to_i`, perhaps) returned `0`. Empty string is irrelevant here. ---------------------------------------- Feature #17773: Alias `Numeric#zero?` and `Float#zero?` as `Numeric#empty?` and `Float#empty?` https://bugs.ruby-lang.org/issues/17773#change-91239 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal ---------------------------------------- When dealing with user input fields as in web applications, there are typical values that we want to consider as the default and/or absence of user input. For string/text inputs, list items, and attributes, we have `String#empty?`, `Array#empty?`, and `Hash#empty?` respectively, which seem to correspond to those cases. As for numerics, there are `Numeric#zero?` and `Float#zero?`. However, there is no single term that covers all these cases. In a routine to check through the fields whether there is user input, we have to selectively use `empty?` or `zero?` depending on the type of the input field. Many programming languages other than Ruby typically consider these values as falsy with respect to logical calculation. Ruby handles only `nil` and `false` as falsy, and that has clear advantages in many aspects, but with the cost of losing a simple way to handle these default values. I propose to alias `Numeric#zero?` as `Numeric#empty?` and `Float#zero?` as `Float#empty?` so that we can simply use `empty?`. At first, calling zero as empty might sound strange, but at least for non-negative integers, set theoretic definitions usually define zero as the empty set, so it is not that strange after all. Ruby on Rails' `blank?` is conceptually similar to this, but `0.blank?` returns `false`, so it is a different concept. -- https://bugs.ruby-lang.org/