From: "José Francisco Calvo Moreno" Date: 2011-11-15T02:44:40+09:00 Subject: [ruby-core:41036] Re: Proposal to add new methods: positive? negative? natural? --000325556062af0c6704b1b56ca5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Chuck, You are right, totally right. I have been thinking about it and I believe that the best solutions is as follow: 1.positive? =3D> true -1.positive? =3D> false 1.negative? =3D> false -1.negative? =3D> true 0.positive? =3D> false 0.negative? =3D> false About zero as you can read at Wikipedia ( http://en.wikipedia.org/wiki/Positive_number) "The number zero is neither positive nor negative, and therefore has no sign", for this reason I think that best solution is to return false in all cases with positive? and negative? when number is zero. With this solution you are respecting at the same time the Principle of Least Surprise with methods ending in question mark and the no sign nature of zero number. The only problem that I see is that not 0.positive? =3D> true could be confusing and you may think that 0 is negative (when it is not). 2011/11/14 Chuck Remes > > On Nov 14, 2011, at 10:54 AM, Jos=E9 Francisco Calvo Moreno wrote: > > > About to add this method to Fixnum, Integer or Numeric you must excuse > me because I'm starting to understand the Ruby Core. I though that Fixnum > is the base of Integer number and adding a C function to it will solve th= e > problem and make the condition faster. About the zero condition, I have m= y > doubts but maybe a solution would be return nil. > > 1.positive? =3D> true > > -1.positive? =3D> false > > 0.positive? =3D> nil (same as false) > > That may break the Principle of Least Surprise for methods ending in a > question mark. In Ruby, nil and false are equivalent for the purposes of > failing a boolean test. The expectation for a method ending in ? is binar= y; > that is, either true or false. There is *no* third possible condition by > tradition. > > A user should not be expected to differentiate between a ? method > returning nil and a method returning false. > > IMHO. > > cr > > > --000325556062af0c6704b1b56ca5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Chuck,

You are right, totally right. =A0I have been t= hinking about it and I believe that the best solutions is as follow:
<= div>
=A01.positive? =3D> true
-1.positive? =3D&g= t; false

=A01.negative? =3D> false
-1.negative? =3D= > true

=A00.positive? =3D> false
= =A00.negative? =3D> false

About zero as you can= read at Wikipedia (http://en.wikipedia.org/wiki/Positive_number) "The number=A0zero=A0is neither positive nor negative, = and therefore has no sign", for this reason I think that best solution= is to return false in all cases with positive? and negative? when number i= s zero. With this solution you are respecting at the same time=A0the= Principle of Least Surprise=A0with methods ending in question mark and the= no sign nature of zero number.

The only problem that I see is that

=A0not 0.positive? =3D> true

could be con= fusing and you may think that 0 is negative (when it is not).
2011/11/14 Chuck Remes <cremes.devlist@mac.com>

On Nov 14, 2011, at 10:54 AM, Jos=E9 Francisco Calvo Moreno wrote:

> About to add this method to Fixnum, Integer or Numeric you must excuse= me because I'm starting to understand the Ruby Core. I though that Fix= num is the base of Integer number and adding a C function to it will solve = the problem and make the condition faster. About the zero condition, I have= my doubts but maybe a solution would be return nil.

1.positive? =3D> true

-1.positive? =3D> false

0.positive? =3D> nil (same as false)

That may break the Principle of Least Surprise for methods ending in a ques= tion mark. In Ruby, nil and false are equivalent for the purposes of failin= g a boolean test. The expectation for a method ending in ? is binary; that = is, either true or false. There is *no* third possible condition by traditi= on.

A user should not be expected to differentiate between a ? method returning= nil and a method returning false.

IMHO.

cr



--000325556062af0c6704b1b56ca5--