Why is there no or or and ?
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Feb 16 20:47:26 PST 2012
On Thu, Feb 16, 2012 at 08:35:38PM -0800, Jonathan M Davis wrote:
> On Thursday, February 16, 2012 22:31:18 Caligo wrote:
> > C++ has this and it makes code little more readable in certain cases:
> >
> > if(something() or foo() and bar()){ ... }
> >
> > instead of this in D:
> >
> > if(something() || foo() && bar()){ ... }
> >
> >
> > possible enhancement request? or is there a good reason it is not in
> > the language?
>
> Since when does C++ have "or" and "and"? C++ uses || and &&, just like C and
> Java and C# and... I'm sure that there's a language somewhere whch uses "or"
> and "and," but I've never used one that did.
You'll be surprised:
http://en.cppreference.com/w/cpp/keywords
I know I was very surprised when I saw this, a few minutes ago. :)
> And I'm actually mildly shocked that anyone (at least any programmer)
> would think that "or" and "and" were more readable. The fact that
> operators aren't words is a _major_ boon to code readibility.
[...]
Well, in that case, we should replace 'in' with '∈'. Certainly,
if (a in A) { ... }
isn't as readable as:
if (a ∈ A) { ... }
Or, for those poor folks who can't easily type ∈, we can write it as (=:
if (a (= A) { ... }
;-)
T
--
Just because you can, doesn't mean you should.
More information about the Digitalmars-d
mailing list