[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02886] Re: Just one more wafer thin mint....

From: "David Douthitt" <DDouthitt@...>
Date: 2000-05-18 13:33:41 UTC
List: ruby-talk #2886
In terms of documenting code,

(n % 2 == 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 == 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 <Dave@Thomases.com> writes:

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

Both

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

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

                            matz.

In This Thread

Prev Next