English binary logic operators

Sean Kelly sean at f4.ca
Wed Nov 8 06:00:49 PST 2006


Bill Baxter wrote:
> Bill Baxter wrote:
>> David Qualls wrote:
> 
>> After 20 years of C/C++ my use of && and || was pretty instinctual, 
>> but after just a few months of working with Python on the side I found 
>> I started typing 'and' and 'or' without thinking about it.  
> 
> I think my meaning wasn't so clear so let me rephrase.
> 
> It took no time to get used to 'and/or' when learning python.  I don't 
> recall ever mistakenly using '&&' in my first few python attempts.  But 
> what happened after a few months (and continues to today) is that I 
> sometimes type 'and/or' in *C++* code (and now *D* too) when I mean &&/||.
> 
> I think it's just because in my head I'm *thinking* 'if this and that' 
> as I type.  My brain recognizes 'and' as a legal keyword from somewhere 
> and so my fingers type it.
> 
> Unfortunately, if && and || are to be eliminated wholesale, the benefit 
> will be seen as too small to be worth the pain of fixing all old code. 
> Furthermore Walter believes that C/C++ syntax must be good enough or it 
> wouldn't have survived so long (or something like that).  And he 
> believes that D should look and behave like C/C++ as much as possible to 
> ease the transition for C/C++ refugees (hence the decision to not fix 
> how switch works).  He also believes that symbols (!@#$%^&*) should be 
> used wherever possible instead of new keywords (hence we have ':' 
> showing up everywhere for all kinds of different purposes, and "static" 
> with even more meanings than in C++).
> 
> It could be possible to add 'and' and 'or' as _synonyms_, but that 
> smacks as too many ways to do the same thing, and adds two keywords for 
> something for which there is already another way to do it.  It doesn't 
> let you do or express anything you couldn't before.

For what it's worth, 'and' and 'or' as synonyms for '&&' and '||' 
already exists in C/C++.  Trigraphs are a largely unknown feature that 
many appear to dislike, but I have read a reasonable argument that they 
are useful for teaching new programmers.  Personally, I think that 
learning the meaning of new symbols is part of learning any language, so 
what's important is really that these symbols be easily recognizable and 
clearly meaningful.  Once you've learned that '&&' represents a logical 
'and' operation, are you liable to forget that or mistake it for 
something else?  Also, binary 'and' (ie. '&') may want a descriptive 
term as well, if we're adding support for the logical operators.  And I 
think that's when things begin to get confusing with the English terms.


Sean



More information about the Digitalmars-d-learn mailing list