Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > print(true and true) #=> the parenthesis issue

Thread Tools

print(true and true) #=> the parenthesis issue

Dave Bass
Posts: n/a
Robert Klemme wrote:
> Exactly. That's why I offered a variant that not only has the same
> semantics as my version with "and" but also reads much better than
> your double negation.

But my double negation is completely and absolutely clear! The whole
point of putting "unless x == false" is that it WON'T respond to nil,
only to false.

The x variable is presumably supposed to be Boolean, i.e. true/false. If
there's a possibility that some_work() could return nil and assign it to
x, it's likely to be because something went wrong within some_work().
That can and should be picked up by a separate test such as "if x.nil?".

It's shortcuts like writing "if x" instead of "unless x == false" that
conceal the potential for bugs. If one means "unless x == false" then
one should write it. If on the other hand one means "unless (x == false
|| x == nil)" then one should write that instead.

Clarity is more important than conciseness.

Posted via

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with regular expressions and parenthesis Daniel Fac Ruby 3 11-02-2008 01:26 AM
What do these dollar signs and parenthesis do? Javascript 14 09-28-2008 09:50 PM
OR and AND without parenthesis IveCal Java 4 06-22-2007 08:07 AM
preprocessor and parenthesis effbiae C Programming 5 02-07-2006 03:22 PM
Regular expressions and parenthesis in match text Carl Cunningham Perl Misc 2 09-15-2003 11:02 AM