From: Fuad Saud Date: 2013-11-23T00:15:40-02:00 Subject: [ruby-core:58517] Re: [ruby-trunk - Feature #9123][Open] Make Numeric#nonzero? behavior consistent with Numeric#zero? --089e0149cede15f21a04ebceb523 Content-Type: text/plain; charset=ISO-8859-1 I don't understand why we would want to be so strict about types on this case. Having some arbitrary value being returned is useful and it doesn't hurt any good practices. Ensuring predicates return true or false feels useless for me On Friday, November 22, 2013, mame (Yusuke Endoh) wrote: > > Issue #9123 has been updated by mame (Yusuke Endoh). > > > avit (Andrew Vit) wrote: > > 42.nonzero? #=> 42 > > 0.nonzero? #=> false > > > In fact, the first version of nonzero? returned self or false. > > Inaba, in [ruby-dev:6417] (22 Mar 1999), suggested a convention about the > usage > of nil and false. > > * if a method returns only a boolean, it should use true and false > * if a method returns a general object but also "false" value, it should > use nil > > Matz accepted it, and adopted the convention to another exception, > defined?. > As far as I know, this is the only spec change of nonzero? ever. > > > Inaba pointed out that a method whose name ends with "?" would make a user > feel > that it should return only a boolean, though he also admitted that it is > difficult > to change because of compatibility issue (in 1999). > Matz agreed, and said that "?" is a symbol that is "mainly used as a > predicate". > > -- > Yusuke Endoh > > ---------------------------------------- > Feature #9123: Make Numeric#nonzero? behavior consistent with Numeric#zero? > https://bugs.ruby-lang.org/issues/9123#change-43094 > > Author: sferik (Erik Michaels-Ober) > Status: Open > Priority: Normal > Assignee: > Category: > Target version: > > > Numeric#zero? returns true or false, while Numeric#nonzero? returns self > or nil. > > I've written a patch that fixes this inconsistency and adds a > Numeric#nonzero (non-predicate) method that returns self or nil for > chaining comparisons. I'd like for this to be included in Ruby 2.1.0. > > https://github.com/ruby/ruby/pull/452.patch > > > -- > http://bugs.ruby-lang.org/ > -- Fuad Saud twitter | linkedin| coderwall | github| --089e0149cede15f21a04ebceb523 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I don't understand why we would want to be so strict about types on thi= s case. Having some arbitrary value being returned is useful and it doesn&#= 39;t hurt any good practices. Ensuring predicates return true or false feel= s useless for me

On Friday, November 22, 2013, mame (Yusuke Endoh) wrote:

Issue #9123 has been updated by mame (Yusuke Endoh).


avit (Andrew Vit) wrote:
> =A0 =A0 42.nonzero? #=3D> 42
> =A0 =A0 0.nonzero? =A0#=3D> false


In fact, the first version of nonzero? returned self or false.

Inaba, in [ruby-dev:6417] (22 Mar 1999), suggested a convention about the u= sage
of nil and false.

=A0 * if a method returns only a boolean, it should use true and false
=A0 * if a method returns a general object but also "false" value= , it should use nil

Matz accepted it, and adopted the convention to another exception, defined?= .
As far as I know, this is the only spec change of nonzero? ever.


Inaba pointed out that a method whose name ends with "?" would ma= ke a user feel
that it should return only a boolean, though he also admitted that it is di= fficult
to change because of compatibility issue (in 1999).
Matz agreed, and said that "?" is a symbol that is "mainly u= sed as a predicate".

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #9123: Make Numeric#nonzero? behavior consistent with Numeric#zero?=
https://bugs.ruby-lang.org/issues/9123#change-43094

Author: sferik (Erik Michaels-Ober)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Numeric#zero? returns true or false, while Numeric#nonzero? returns self or= nil.

I've written a patch that fixes this inconsistency and adds a Numeric#n= onzero (non-predicate) method that returns self or nil for chaining compari= sons. I'd like for this to be included in Ruby 2.1.0.

h= ttps://github.com/ruby/ruby/pull/452.patch


--
http://bugs.ruby-l= ang.org/


--
Fuad Saud
<= div style=3D"text-align:left">


--089e0149cede15f21a04ebceb523--