digitalmars.D.learn - and/or/not/xor operators
- Shriramana Sharma (21/21) May 30 2013 Hello. I have always loved the readability of C++'s and/or/not/xor
- Iain Buclaw (2/7) May 30 2013 No, it isn't available... Thank goodness! :)
- ixid (3/12) May 30 2013 Why thank goodness? This would seem to significantly aid
- Regan Heath (10/20) May 31 2013 IMO it makes D more complex for insufficient gain. It takes very little...
- ixid (4/10) May 31 2013 Up to a point I'd certainly agree with that, however in this case
- Regan Heath (15/27) Jun 03 2013 I can't recall ever being confused by &&.. in fact, I got my first
- ixid (13/44) Jun 04 2013 I think you're coming from a position of what is rather than what
- Regan Heath (6/54) Jun 05 2013 Yes. I am, and every other C and C++ programmer is. Just about no-one ...
- John Colvin (11/78) Jun 05 2013 Although I love the easy-to-read properties of and/or, I always
- bearophile (10/14) May 30 2013 and/or/not are less visually noisy, they look better than the
- Shriramana Sharma (19/22) May 30 2013 Thanks to all who replied.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (11/15) May 30 2013 Are there others in the team?
- bearophile (8/12) May 30 2013 Beside the && || ! I think it's much better to not replace the
- bearophile (18/30) May 30 2013 I prefer the Python design here, it uses & | ^ for bitwise
- Regan Heath (11/21) May 31 2013 Until this thread I didn't even know they existed.. and I've been coding...
- bearophile (18/22) May 31 2013 Finding a short, common and easy to write English word "ugly" is
- John Colvin (5/6) May 31 2013 Same.
- Minas Mina (2/17) May 31 2013 They are more noisy for non-English talking persons.
- Shriramana Sharma (6/6) May 31 2013 T24gRnJpLCBNYXkgMzEsIDIwMTMgYXQgNDoxMiBQTSwgTWluYXMgTWluYQ0KPG1pbmFzX21p...
- John Colvin (6/24) May 30 2013 For better or worse, we don't have those keywords in D and are
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. --=20 Shriramana Sharma =E0=AE=B6=E0=AF=8D=E0=AE=B0=E0=AF=80=E0=AE=B0=E0=AE=AE=E0= =AE=A3=E0=AE=B6=E0=AE=B0=E0=AF=8D=E0=AE=AE=E0=AE=BE =E0=A4=B6=E0=A5=8D=E0= =A4=B0=E0=A5=80=E0=A4=B0=E0=A4=AE=E0=A4=A3=E0=A4=B6=E0=A4=B0=E0=A5=8D=E0=A4= =AE=E0=A4=BE
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
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:Why thank goodness? This would seem to significantly aid readability and comprehension.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
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:IMO it makes D more complex for insufficient gain. It takes very little 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/On Thursday, 30 May 2013 at 16:18:44 UTC, Shriramana Sharma wrote:Why thank goodness? This would seem to significantly aid readability and comprehension.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 31 2013
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. RUp to a point I'd certainly agree with that, however in this case I think the advantages outweigh the penalty. These operators are self-documenting, no one will need to look up 'and' and gain readability, language accessibility and beauty.
May 31 2013
On Fri, 31 May 2013 21:26:56 +0100, ixid <nuaccount gmail.com> wrote:Not for me, and I suspect others too.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. RUp to a point I'd certainly agree with that, however in this case I think the advantages outweigh the penalty.These operators are self-documenting, no one will need to look up 'and'I can't recall ever being confused by &&.. in fact, I got my first programming job (an apprentice position) by describing some C code (a language I had never used/seen before) using && and I immediately guess what it meant, it was obvious from the context.and gain readabilityTo me using "and" would reduce parsability (as in by my human eyes) and that would hamper readability, for me.language accessibilityAny programmer that does not understand && needs to be educated, period. Once that happens they can code in numerous other languages, so win-win.beauty.I don't find && ugly, in fact I would go so far as to say that code using "and" would be less pleasant to my eyes. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Jun 03 2013
On Monday, 3 June 2013 at 09:29:20 UTC, Regan Heath wrote:On Fri, 31 May 2013 21:26:56 +0100, ixid <nuaccount gmail.com> wrote:I think you're coming from a position of what is rather than what can be. You're practiced with && so it appears more normal than it is. a and b is far clearer than a && b especially as you add more terms: a and b or c versus a && b || c Which is just symbolic gibberish to anyone beginning programming. Digraphs are almost as bad as trigraphs.Not for me, and I suspect others too.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. RUp to a point I'd certainly agree with that, however in this case I think the advantages outweigh the penalty.These operators are self-documenting, no one will need to look up 'and'I can't recall ever being confused by &&.. in fact, I got my first programming job (an apprentice position) by describing some C code (a language I had never used/seen before) using && and I immediately guess what it meant, it was obvious from the context.and gain readabilityTo me using "and" would reduce parsability (as in by my human eyes) and that would hamper readability, for me.language accessibilityAny programmer that does not understand && needs to be educated, period. Once that happens they can code in numerous other languages, so win-win.beauty.I don't find && ugly, in fact I would go so far as to say that code using "and" would be less pleasant to my eyes. R
Jun 04 2013
On Tue, 04 Jun 2013 23:47:07 +0100, ixid <nuaccount gmail.com> wrote:On Monday, 3 June 2013 at 09:29:20 UTC, Regan Heath wrote:Yes. I am, and every other C and C++ programmer is. Just about no-one is practiced with "and" or "or" in a programming language.On Fri, 31 May 2013 21:26:56 +0100, ixid <nuaccount gmail.com> wrote:I think you're coming from a position of what is rather than what can be. You're practiced with && so it appears more normal than it is.Not for me, and I suspect others too.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. RUp to a point I'd certainly agree with that, however in this case I think the advantages outweigh the penalty.These operators are self-documenting, no one will need to look up 'and'I can't recall ever being confused by &&.. in fact, I got my first programming job (an apprentice position) by describing some C code (a language I had never used/seen before) using && and I immediately guess what it meant, it was obvious from the context.and gain readabilityTo me using "and" would reduce parsability (as in by my human eyes) and that would hamper readability, for me.language accessibilityAny programmer that does not understand && needs to be educated, period. Once that happens they can code in numerous other languages, so win-win.beauty.I don't find && ugly, in fact I would go so far as to say that code using "and" would be less pleasant to my eyes. Ra and b is far clearer than a && bNo, it's really not (for me).especially as you add more terms: a and b or c versus a && b || cThe latter is still clearer (to me). R
Jun 05 2013
On Wednesday, 5 June 2013 at 09:02:44 UTC, Regan Heath wrote:On Tue, 04 Jun 2013 23:47:07 +0100, ixid <nuaccount gmail.com> wrote:Although I love the easy-to-read properties of and/or, I always find they make it too tempting to read the code as english instead of formal logic. E.g. a and b or b and c vs. a && b || b && c For me, the latter reminds me that I need to specify precedence whereas with the former it's just too easy to place the emphasis yourself like you do when reading prose.On Monday, 3 June 2013 at 09:29:20 UTC, Regan Heath wrote:Yes. I am, and every other C and C++ programmer is. Just about no-one is practiced with "and" or "or" in a programming language.On Fri, 31 May 2013 21:26:56 +0100, ixid <nuaccount gmail.com> wrote:I think you're coming from a position of what is rather than what can be. You're practiced with && so it appears more normal than it is.Not for me, and I suspect others too.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. RUp to a point I'd certainly agree with that, however in this case I think the advantages outweigh the penalty.These operators are self-documenting, no one will need to look up 'and'I can't recall ever being confused by &&.. in fact, I got my first programming job (an apprentice position) by describing some C code (a language I had never used/seen before) using && and I immediately guess what it meant, it was obvious from the context.and gain readabilityTo me using "and" would reduce parsability (as in by my human eyes) and that would hamper readability, for me.language accessibilityAny programmer that does not understand && needs to be educated, period. Once that happens they can code in numerous other languages, so win-win.beauty.I don't find && ugly, in fact I would go so far as to say that code using "and" would be less pleasant to my eyes. Ra and b is far clearer than a && bNo, it's really not (for me).especially as you add more terms: a and b or c versus a && b || cThe latter is still clearer (to me). R
Jun 05 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
Thanks to all who replied. On Thu, May 30, 2013 at 10:18 PM, bearophile <bearophileHUGS lycos.com> wro= te: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 wi=llsee 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. --=20 Shriramana Sharma =E0=AE=B6=E0=AF=8D=E0=AE=B0=E0=AF=80=E0=AE=B0=E0=AE=AE=E0= =AE=A3=E0=AE=B6=E0=AE=B0=E0=AF=8D=E0=AE=AE=E0=AE=BE =E0=A4=B6=E0=A5=8D=E0= =A4=B0=E0=A5=80=E0=A4=B0=E0=A4=AE=E0=A4=A3=E0=A4=B6=E0=A4=B0=E0=A5=8D=E0=A4= =AE=E0=A4=BE
May 30 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 30 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 30 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 30 2013
On Fri, 31 May 2013 02:41:14 +0100, Shriramana Sharma <samjnaa gmail.com> wrote:Thanks to all who replied. On Thu, May 30, 2013 at 10:18 PM, bearophile <bearophileHUGS lycos.com> wrote:Until this thread I didn't even know they existed.. and I've been coding in C++ for ~12 years. I suspect people who came to C++ from C (as I did) would not learn about them, because they are simply alternate syntax for something they already know and use. I find them ugly and less clear - because I can glance at words & symbols and immediately see the operator, faster than with words and symbols. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/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?
May 31 2013
Regan Heath:I find them ugly and less clear - because I can glance at words & symbols and immediately see the operator, faster than with words and symbols.Finding a short, common and easy to write English word "ugly" is quite strange, especially for a person that seems able to write in English. In C code it's not uncommon to write "&" where you meant "&&" by mistake and vice versa (so common that all the lint tools I know of have rules to spot such kind of bug). And for most kinds of not low-level programming bitwise operators are far less commonly used than boolean operators. So it's a good idea to visually differentiate them more. Maybe if you program in Python a little you will appreciate my opinion :-) --------------- Minas Mina:They are more noisy for non-English talking persons.<It's hard to believe, it's the first time I hear that. I have no reliable studies on this topic. Bye, bearophile
May 31 2013
On Friday, 31 May 2013 at 10:21:19 UTC, Regan Heath wrote:Until this thread I didn't even know they existed..Same. I use them every day in python, but I had no idea they were in C++ Tbh they annoy me in python, although that's just my C background showing.
May 31 2013
On Thursday, 30 May 2013 at 16:48:33 UTC, bearophile wrote:Shriramana Sharma:They are more noisy for non-English talking persons.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 31 2013
T24gRnJpLCBNYXkgMzEsIDIwMTMgYXQgNDoxMiBQTSwgTWluYXMgTWluYQ0KPG1pbmFzX21pbmEx OTkwQGhvdG1haWwuY28udWs+IHdyb3RlOg0KPiBUaGV5IGFyZSBtb3JlIG5vaXN5IGZvciBub24t RW5nbGlzaCB0YWxraW5nIHBlcnNvbnMuDQoNClVtIGFuZCB0aGUgcmVzdCBvZiB0aGUgRCBrZXl3 b3JkcyBhcmUgaW4gd2hhdCBsYW5ndWFnZT8hDQoNCi0tIA0KU2hyaXJhbWFuYSBTaGFybWEg4K62 4K+N4K6w4K+A4K6w4K6u4K6j4K624K6w4K+N4K6u4K6+IOCktuCljeCksOClgOCksOCkruCko+Ck tuCksOCljeCkruCkvg0K
May 31 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 30 2013