Recently I was pretty surprised to see the code instead of the usual && and || keywords and and or . The question arises: why are they so rarely used, because readability is obviously higher, and no difference, judging by the documentation?

  • 3
    readability is obviously higher - oh not obvious ... - PinkTux
  • Well, the C language appeared in the early 70s, and and and or appeared in the 1999 language standard. You think those who write textbooks will quickly retrain, and why, in fact, everyone has become accustomed - Mike
  • BTW, and_eq and or_eq I associate exclusively with "and equals" and "or equal", and not with bit operations :-) - PinkTux
  • 3
    If you do not like ? || && -> * ? || && -> * ? || && -> * etc. Can you just use another language? (and we just got used to them and fell in love with such compact designations) - avp

1 answer 1

As they say, habit is second nature. :)

The point is that in C, these tokens are not keywords. They are macros that are defined in the <iso646.h> header file. Therefore, to use them, you need to include this file, which adds to the work of programmers. :)

If you write programs only in C ++, the use of these keywords sometimes makes the code more readable. For example, personally, I have long adopted to write not instead of the negation operator ! , since the latter is sometimes difficult to distinguish in expressions containing numerous brackets.

Not to be unsubstantiated, I will provide a link to my answer to SO , where in the bubble sort function I use the keyword not .

The keywords and and or are also good candidates for incorporating them into their arsenal when writing logical expressions. I sometimes use them too. :)

  • and and or is not recommended for those who work in parallel with the pearl at least :) - PinkTux
  • @PinkTux I think Perl has no effect on how to write code in C ++. - Vlad from Moscow
  • It also provides. And vice versa. especially when the work is not just parallel, but joint (for example, xs). The letters are the same, but the meaning is different. However, if there are no problems with instant context switching in the head, then you can write anything and anything ... - PinkTux
  • @PinkTux This is just a special case where the same programmer is equally loaded with C ++ and Perl and has to combine object modules written in these languages ​​into one project. As for C ++ and C, their development will be coordinated by the standardization committees, and this is common when a programmer needs to write code in C ++ and C in one project. - Vlad from Moscow
  • This is just a special case when the same programmer is equally loaded with C ++ and Perl - did I write something fundamentally different from this in the first comment? - PinkTux