ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: sawadatsuyoshi@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:103186] [Ruby master Feature#17773] Alias `Numeric#zero?` and `Float#zero?` as `Numeric#empty?` and `Float#empty?`
Date: Fri, 02 Apr 2021 14:40:07 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-91261.20210402144007.2963@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17773.20210402034945.2963@ruby-lang.org

Issue #17773 has been updated by sawa (Tsuyoshi Sawada).


You may be right that zero is not (the only) special (element). In fact, one is the unit element for multiplication whereas zero is the unit element for addition. But still, addition is the first operation, and is more prominent than multiplication, which is the second operation. And the fact that we already have `zero?` method and the fact that many languages handle zero as falsy seem to indicate that indeed zero is special.

Regarding -1 representing emptiness, I cannot recall clear instances. (Perhaps related to some sort of perpendicularity?) Can you give me some ideas?

----------------------------------------
Feature #17773: Alias `Numeric#zero?` and `Float#zero?` as `Numeric#empty?` and `Float#empty?`
https://bugs.ruby-lang.org/issues/17773#change-91261

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

  parent reply	other threads:[~2021-04-02 14:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02  3:49 [ruby-core:103162] [Ruby master Feature#17773] Alias `Numeric#zero?` and `Float#zero?` as `Numeric#empty?` and `Float#empty?` sawadatsuyoshi
2021-04-02  4:24 ` [ruby-core:103164] " merch-redmine
2021-04-02  5:23 ` [ruby-core:103165] " sawadatsuyoshi
2021-04-02  5:42 ` [ruby-core:103166] " sawadatsuyoshi
2021-04-02  6:21 ` [ruby-core:103167] " muraken
2021-04-02  7:21 ` [ruby-core:103171] " marcandre-ruby-core
2021-04-02 10:09 ` [ruby-core:103175] " eregontp
2021-04-02 14:40 ` sawadatsuyoshi [this message]
2021-04-02 15:39 ` [ruby-core:103188] " xtkoba+ruby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-91261.20210402144007.2963@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).