From: David Douthitt Date: 2000-05-18T08:33:41-05:00 Subject: [ruby-talk:02886] Re: Just one more wafer thin mint.... This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=_DA82CD59.F998FC3A Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable In terms of documenting code, (n % 2 =3D=3D 1) is *much* less satisfactory than (n.even?) And in any case, sometimes the first equation could mean different things = (even though the result is identical). For instance: (n.valve_open?) could have the same meaning if the last bit is being tested for being one = or zero. If you use the first equation, none of this can be seen in the = code. However, matz's point comes into its own here: why not use def even? n % 2 =3D=3D 1 end ?? The only thing gained otherwise would be machine optimization. David Douthitt UNIX Systems Administrator ddouthitt@cuna.com (608) 231-4922 >>> matz@netlab.co.jp 5/17/00 9:11p >>> The following message is a courtesy copy of an article that has been posted to comp.lang.ruby as well. Hi, Finally, I got access to comp.lang.ruby. Dave Thomas writes: |Does anyone else think that Integer#odd? would be useful? Both n % 2 =3D=3D 1 (n ^ 1) =3D=3D 1 would work. Do we really need it? If I have to add odd?, I'd add even? too. matz. --=_DA82CD59.F998FC3A Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
In terms of documenting code,
 
(n % 2 =3D=3D 1)
 
is *much* less satisfactory than
 
(n.even?)
 
And in any case, sometimes the first equation could = mean=20 different things (even though the result is identical).  For=20 instance:
 
(n.valve_open?)
 
could have the same meaning if the last bit is being = tested=20 for being one or zero.  If you use the first equation, none of this = can be=20 seen in the code.
 
However, matz's point comes into its own here: why = not=20 use
 
def even?
   n % 2 =3D=3D 1
end
 
??  The only thing gained otherwise would be = machine=20 optimization.
 
David Douthitt
UNIX Systems Administrator
ddouthitt@cuna.com
(608)=20 231-4922

>>> matz@netlab.co.jp 5/17/00 9:11p >>>
The= =20 following message is a courtesy copy of an article
that has been posted = to=20 comp.lang.ruby as well.

Hi,

Finally, I got access to=20 comp.lang.ruby.

Dave Thomas <Dave@Thomases.com>=20 writes:

|Does anyone else think that Integer#odd? would be=20 useful?

Both

  n % 2 =3D=3D 1
  (n ^ 1) =3D=3D = 1

would=20 work.  Do we really need it?
If I have to add odd?, I'd add = even?=20 too.

           =20                = =20 matz.
--=_DA82CD59.F998FC3A--