From: xtkoba+ruby@... Date: 2021-04-02T15:39:09+00:00 Subject: [ruby-core:103188] [Ruby master Feature#17773] Alias `Numeric#zero?` and `Float#zero?` as `Numeric#empty?` and `Float#empty?` Issue #17773 has been updated by xtkoba (Tee KOBAYASHI). An example of using `-1` as a default-ish integer value is to indicate "item not found" in a C-like language (see https://en.wikipedia.org/wiki/Sentinel_value). The following example seems to suggest that Ruby treats `0` as a default-ish integer value in some cases. ```ruby p nil.to_i # => 0 p "".to_i # => 0 ``` Yet I don't think that `0` should be treated as the special value in general, as long as we can freely assign both `nil` and an integer value to the same variable. ---------------------------------------- Feature #17773: Alias `Numeric#zero?` and `Float#zero?` as `Numeric#empty?` and `Float#empty?` https://bugs.ruby-lang.org/issues/17773#change-91263 * 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/ Unsubscribe: