Jump to page: 1 2
Thread overview
and/or/not/xor operators
May 30, 2013
Shriramana Sharma
May 30, 2013
Iain Buclaw
May 30, 2013
ixid
May 31, 2013
Regan Heath
May 31, 2013
ixid
Jun 03, 2013
Regan Heath
Jun 04, 2013
ixid
Jun 05, 2013
Regan Heath
Jun 05, 2013
John Colvin
May 30, 2013
bearophile
May 31, 2013
Shriramana Sharma
May 31, 2013
Ali Çehreli
May 31, 2013
bearophile
May 31, 2013
bearophile
May 31, 2013
Regan Heath
May 31, 2013
bearophile
May 31, 2013
John Colvin
May 31, 2013
Minas Mina
May 31, 2013
Shriramana Sharma
May 30, 2013
John Colvin
May 30, 2013
Hello. I have always loved the readability of C++'s and/or/not/xor word-like logical operators but It doesn't seem to be available in D. Isn't this possible in D? I tried doing:

alias && and ;
import std.stdio ;
void main () {
	writeln ( true and true ) ;
}

but I get errors:

$ dmd foo.d
foo.d(1): Error: basic type expected, not &&
foo.d(1): Error: no identifier for declarator int
foo.d(1): Error: semicolon expected to close alias declaration
foo.d(1): Error: Declaration expected, not '&&'
foo.d(7): Error: found 'and' when expecting ',

Thanks.

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
May 30, 2013
On Thursday, 30 May 2013 at 16:18:44 UTC, Shriramana Sharma wrote:
> Hello. I have always loved the readability of C++'s and/or/not/xor
> word-like logical operators but It doesn't seem to be available in D.
> Isn't this possible in D? I tried doing:
>

No, it isn't available... Thank goodness! :)
May 30, 2013
Shriramana Sharma:

> Hello. I have always loved the readability of C++'s and/or/not/xor
> word-like logical operators but It doesn't seem to be available in D.

and/or/not are less visually noisy, they look better than the ugly &&/||/! of C/C++/D, and it's much less easy to write & when you need && or vice versa, so they are also less bug-prone, as Python shows. On this Python syntax got it better than D.

But Walter refused them time ago on the basis that no one uses them in C++. So you can ask for them in the main D newsgroup, but I don't think you will see them in D...

Bye,
bearophile
May 30, 2013
On Thursday, 30 May 2013 at 16:30:12 UTC, Iain Buclaw wrote:
> On Thursday, 30 May 2013 at 16:18:44 UTC, Shriramana Sharma wrote:
>> Hello. I have always loved the readability of C++'s and/or/not/xor
>> word-like logical operators but It doesn't seem to be available in D.
>> Isn't this possible in D? I tried doing:
>>
>
> No, it isn't available... Thank goodness! :)

Why thank goodness? This would seem to significantly aid readability and comprehension.
May 30, 2013
On Thursday, 30 May 2013 at 16:18:44 UTC, Shriramana Sharma wrote:
> Hello. I have always loved the readability of C++'s and/or/not/xor
> word-like logical operators but It doesn't seem to be available in D.
> Isn't this possible in D? I tried doing:
>
> alias && and ;
> import std.stdio ;
> void main () {
> 	writeln ( true and true ) ;
> }
>
> but I get errors:
>
> $ dmd foo.d
> foo.d(1): Error: basic type expected, not &&
> foo.d(1): Error: no identifier for declarator int
> foo.d(1): Error: semicolon expected to close alias declaration
> foo.d(1): Error: Declaration expected, not '&&'
> foo.d(7): Error: found 'and' when expecting ',
>
> Thanks.

For better or worse, we don't have those keywords in D and are unlikely to get them.

Also, alias is not the same as the C preprocessor, you can't redefine any arbitrary string you want. http://dlang.org/declaration.html#alias
May 31, 2013
Thanks to all who replied.

On Thu, May 30, 2013 at 10:18 PM, bearophile <bearophileHUGS@lycos.com> wrote:
>
> But Walter refused them time ago on the basis that no one uses them in C++. So you can ask for them in the main D newsgroup, but I don't think you will see them in D...

Um why really? "No one uses them in C++"? How come? I agree that Walter has succesfully produced/marketed a C++ compiler for a long time, but really, "no one uses"?!!! I use, for one. And it does tremendously increase the readability of a program. Otherwise why would there be a separate C header ever since 1990 for that: http://en.wikipedia.org/wiki/Iso646.h

I agree that we should retain the old operators for C compatibility but really at least the basic and/or/not/xor keywords should be provided.

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
May 31, 2013
On 05/30/2013 06:41 PM, Shriramana Sharma wrote:

> "no one uses"?!!! I use, for one.

Are there others in the team?

Without getting into the argument of whether they are useful, you are the first person that I know who uses them. :) I have been programming in C since 1988 and in C++ since 1997. I have read a lot of books (mostly on C++), frequented the C++ newsgroups for years and years, and did work at many C and C++ companies. I have never seen those keywords used.

> I agree that we should retain the old operators for C compatibility
> but really at least the basic and/or/not/xor keywords should be
> provided.

I don't have a preference on the topic but it would still be incomplete, right? There are many other operators that don't have keywords. Perhaps that's why not many people use them.

Ali

May 31, 2013
Shriramana Sharma:

> Um why really? "No one uses them in C++"? How come? I agree that
> Walter has succesfully produced/marketed a C++ compiler for a long
> time, but really, "no one uses"?!!! I use, for one. And it does
> tremendously increase the readability of a program. Otherwise why
> would there be a separate C header ever since 1990 for that:
> http://en.wikipedia.org/wiki/Iso646.h
>
> I agree that we should retain the old operators for C compatibility
> but really at least the basic and/or/not/xor keywords should be
> provided.

I prefer the Python design here, it uses & | ^ for bitwise operators and and or not for the boolean operations. But I asked to Walter and that's the official answer I received.

Python doesn't support && || ! at all, so you are asking to introduce duplicated syntax in D.

In D learn we help newbies, discuss bugs in user code, library code or in the compiler, sometimes we even propose problems to solve or small functions to add to Phobos, but this is not the right newsgroup to ask for new D syntax. If you are passionate about your request, then you should ask about it in the main D newsgroup. But don't expect to receive a "yes sure!" as answer :-) If you think many C++ programmers are using or and not, then it's much better for you to show evidence. Just saying "I use it!" is (rightfully) not enough for Walter. I read enough C++ code, and I don't see them used often.

Bye,
bearophile
May 31, 2013
Ali Çehreli:

> I don't have a preference on the topic but it would still be incomplete, right? There are many other operators that don't have keywords.

Beside the && || ! I think it's much better to not replace the other operators with keywords.


> Perhaps that's why not many people use them.

I don't know why people don't use them in C++. Python programmers are usually happy to not use && || !. Maybe they prefer to stick to one single common way to do something.

Bye,
bearophile
May 31, 2013
On Thu, 30 May 2013 18:57:37 +0100, ixid <nuaccount@gmail.com> wrote:

> On Thursday, 30 May 2013 at 16:30:12 UTC, Iain Buclaw wrote:
>> On Thursday, 30 May 2013 at 16:18:44 UTC, Shriramana Sharma wrote:
>>> Hello. I have always loved the readability of C++'s and/or/not/xor
>>> word-like logical operators but It doesn't seem to be available in D.
>>> Isn't this possible in D? I tried doing:
>>>
>>
>> No, it isn't available... Thank goodness! :)
>
> Why thank goodness? This would seem to significantly aid readability and comprehension.

IMO it makes D more complex for insufficient gain.  It takes very little time to learn || && etc and once you do you can code in C, Java, C# ..

We really don't want D to become a TMTOWTDI language.  Ideally there should be 1 right way and no alternatives.  That way, anyone who knows D will have a greater chance of knowing what any given code sample does, and not have to look up alternate syntax etc.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
« First   ‹ Prev
1 2