| Thread overview | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
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.
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.
- Jonathan M Davis
| ||||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
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. | ||||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
On Thu, Feb 16, 2012 at 10:35 PM, Jonathan M Davis <jmdavisProg@gmx.com> 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.
>
> 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.
>
> - Jonathan M Davis
In C++ 'and' and 'or', among many others, are alternative logical operators for && and ||.
| ||||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
http://en.cppreference.com/w/cpp/language/operator_alternative | ||||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
Attachments:
| On Thu, Feb 16, 2012 at 9:35 PM, Jonathan M Davis <jmdavisProg@gmx.com>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.
>
> 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.
>
> - Jonathan M Davis
>
They are in the 1998 standard (section 2.5, right below trigraphs, if you are curious). Nobody actually uses them.
Regards,
Brad Anderson
| |||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
On Thursday, February 16, 2012 21:52:35 Brad Anderson wrote:
> On Thu, Feb 16, 2012 at 9:35 PM, Jonathan M Davis
> They are in the 1998 standard (section 2.5, right below trigraphs, if you
> are curious). Nobody actually uses them.
Yuck. That's horrible to hear. I should certainly hope that no one uses them. Having two operators for the same thing is horrific, and words are definitely worse than symbols as far as readibility goes.
- Jonathan M Davis
| ||||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 2/16/2012 8:35 PM, Jonathan M Davis wrote:
> Since when does C++ have "or" and "and"?
Since C++98!
(Amazing but true.)
| |||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On 2/16/2012 8:47 PM, H. S. Teoh wrote:
> Well, in that case, we should replace 'in' with '∈'.
I would, but that doesn't work because of keyboarding issues.
| |||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 2/16/2012 8:54 PM, Jonathan M Davis wrote:
> Yuck. That's horrible to hear. I should certainly hope that no one uses them.
> Having two operators for the same thing is horrific, and words are definitely
> worse than symbols as far as readibility goes.
Well, it sounded like a good idea at the time :-)
| |||
February 17, 2012 Re: Why is there no or or and ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Thu, Feb 16, 2012 at 09:00:39PM -0800, Walter Bright wrote: > On 2/16/2012 8:47 PM, H. S. Teoh wrote: > >Well, in that case, we should replace 'in' with '∈'. > > I would, but that doesn't work because of keyboarding issues. I wasn't being serious. I was going to suggest to those who complain about && being too similar to &, that we should adopt ∧ and ∨ instead. Nice and readable, and unambiguous. And we could use ∀ instead of 'foreach'; that would save so much typing! I mean, D is already standardized on Unicode, why not take advantage of all those nice symbols that Unicode provides? ;-) (As long as you don't mention APL, everybody will be just fine.) T -- If you think you are too small to make a difference, try sleeping in a closed room with a mosquito. -- Jan van Steenbergen | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply