2

Why are the written versions of the logical operators not more widely used? I understand why they exist (to eliminate problems associated with QWERTY keyboards in the early days of programming), but they seem like a syntactic sugar to otherwise "ugly" operators. In this day of auto and range based for-loops, it seems counter intuitive to use a an "ugly" operator when and and or are available.

Surely and is more intuitive to a beginning C++ student than &&. Likewise with or being equivalent to ||.

I've found this answer, particularly the following blockquote enlightening:

...As for their use: because they are rarely used, using them is often more surprising and confusing than it is helpful. I'm sure if it were normal, they would be much easier to read, but people are so used to && and || anything else just gets distracting.

Which basically says to me "people don't use them so they don't expect them", which seems strange to be because and (to me, at least) is more intuitive than using &&.

Community
  • 1
  • 1
Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47
  • I feel that this question is primarily opinion based... – yizzlez Jun 09 '14 at 15:35
  • 4
    Most likely as Potatoswatter comments on my answer [people will be surprised to see them used](http://stackoverflow.com/questions/17365271/and-and-operator/18186331#18186331) since they are not widely known. – Shafik Yaghmour Jun 09 '14 at 15:35
  • Indeed. Any time someone uses one on SO, there's inevitably someone else who claims it's not valid C++. – chris Jun 09 '14 at 15:36
  • 1
    Even if you _know_ that they exist (which not everyone does), "alternative" sounds discouraging compared to "primary". If I have a "primary" option, why should I use the "alternative"? I have absolutely no reason to refuse the primary version, and all the great C++ books I've read use it. I simply have no incentive at all to change. – Daniel Daranas Jun 09 '14 at 15:39
  • @Daniel This is an argument akin to “begging the question”. Your argument for not changing is somewhat circular. The solution is simply not to call them “alternative” in polite conversation, and start using them. Then the “problem” with them goes away. What’s the incentive? How about: every other non-C-derived programming language chose to go with “proper” logical operators. – Konrad Rudolph Jun 09 '14 at 15:41
  • 3
    The better question would be: "Why to these exist at all, since the need for them was gone long before they were invented?" The answer is: they're a nearly perfect example of the second-system effect in action. Useless nonsense with no real use except to fix a problem that hasn't existed in decades. – Jerry Coffin Jun 09 '14 at 15:41
  • @KonradRudolph The C++ standard calls them alternative, not me in polite conversation. They _are_ alternative tokens. – Daniel Daranas Jun 09 '14 at 15:42
  • @Daniel Sure. But the standard neither encourages nor discourages them. Only usage dictates that. – Konrad Rudolph Jun 09 '14 at 15:45

1 Answers1

2

I use them, and I urge people to use them, too. That’s really all there is to it. The reason for few people using them is (a) historical and (b) Visual C++ does not recognise them, and requires the user to include <ciso646>. That’s a bug which Microsoft recognises but refuses to fix.

That’s really all there is to say about them.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1
    Wow... Just... ouch. I never knew these weren't supported by VC++. – chris Jun 09 '14 at 15:37
  • It should be noted that Microsoft never recognized it as a bug, just a design decision. – JasonMArcher Jun 17 '14 at 20:47
  • @Jason True, but Microsoft is simply wrong. They advertise a compliant C++ compiler ([minus some well-specified, justified features](http://stackoverflow.com/a/5416981/1968)). They are lying. – Konrad Rudolph Jun 18 '14 at 16:33