On Aug 15, 2006, at 15:05, Daniel Schierbeck wrote:

> Matthew Smillie wrote:
>> if     X != Y # X not equal to Y
>> unless X == Y # X equal to Y
>> You can pick the one that's more linguistically appealing to you,  
>> though I have a hunch that 'if' is more popular than 'unless'.
>
> I only think that's because most other languages don't have  
> `unless' :)

That was my first intuition too, and I'm certain that's part of it,  
but upon further reflection I think there's more to it as well.  To  
make an if and unless statement equivalent, you have to negate the  
condition, leading to this basic schema:

(1) if X != Y  <-->  unless X == Y
(2) if X == Y  <-->  unless X != Y

Logically, everything's kosher, but linguistically there's a crucial  
difference: the 'unless' form of (2) is a double negative.  I'm sure  
people are generally familiar with the admonition to avoid double  
negatives in their writing, and it's for a good reason: people have a  
hard time understanding multiple negations; to be fair, two is  
usually not a problem, especially in familiar forms such as "not  
unlike X", but in general it's not an easy task to not do  
incorrectly. (see?)

So, if you assume that given the choice people won't use  
linguistically-uncomfortable code, then there are two basic  
comfortable 'if' forms, but only one comfortable 'unless' form.   
Given the lovely, literary nature of Ruby code, this seems like a  
reasonable assumption to make; so even if everyone were perfectly  
familiar with 'unless' as a language construct, you'd still expect  
'if' to outnumber 'unless'.

Not that I think this has much bearing on the language, just a neat  
observation.

matthew smillie

[1] For an entertaining example, see the Language Log talking about a  
Penny Arcade comic strip here:
http://itre.cis.upenn.edu/~myl/languagelog/archives/003437.html