English binary logic operators

Sean Kelly sean at f4.ca
Tue Nov 14 08:37:10 PST 2006

Bruno Medeiros wrote:
> Sean Kelly wrote:
>> 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.  
> What do C trigraphs have to do with 'and' and 'or' as synonyms for '&&' 
> and '||'?

Nothing :-p  I was confusing two similar but unrelated language features.


More information about the Digitalmars-d-learn mailing list