English binary logic operators

Bill Baxter dnewsgroup at billbaxter.com
Tue Nov 7 16:25:04 PST 2006

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.

So in short, it's pretty hopeless.  But I agree it would make the code 
more readable and make overall for a more aesthetically pleasing 
language.  Maybe it could be considered for a backwards-incompatible D 
2.0.  Maybe D 2.0 will have a way to redefine or alias keywords so you 
could just "import std.english_keywords" to get that functionality.  The 
problem with that will be that Walter really likes for D to be easy to 
parse, and part of that is being able to recognize tokens as keywords 
immediately without any special complicated logic.

But I'm with you.  It would be nice to see in D 2.0.

One thing the NumPy folks did as they made lots of changes prior to 1.0 
was to keep a 'convertCode' script up to date with each change.  For 
most cases just running 'convertCode' on your source files is enough to 
get you pretty close to compatible with the latest code.


More information about the Digitalmars-d-learn mailing list