Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use "&&" or "and"? [closed]

I'm using C++11 and both are compiling without any warning, witch one is the best way to do it?

if(a && b)

or

if(a and b)
like image 313
Thomas Ayoub Avatar asked Jun 14 '13 14:06

Thomas Ayoub


People also ask

Should I use in a sentence?

Examples: “You should stop eating fast food.” “You should go for walks more often.” “We should go to the park tomorrow.”

Should I use or used?

Use to + verb is a regular verb and means something that happened but doesn't happen any more. It uses -ed to show past tense. But since it always means something that happened in the past, it should always use past tense. For example- I used to go to school in Paris.

Should I or I should?

It depends on whether you're making a statement or asking a question. If it's a statement, the format is I should. I should be there by noon. It's just the regular verb format - I should or I can or I will.

Where to use should I?

Should is used to say that something is the proper or best thing to do, or to say that someone ought to do something or must do something. Adam could visit us on Monday. This tells us that it is possible Adam will visit on Monday, maybe he can visit us, but maybe he has other options, too.


2 Answers

2.6 Alternative tokens [lex.digraph]

1 Alternative token representations are provided for some operators and punctuators.16

2 In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling.17 The set of alternative tokens is defined in Table 2.

Can't paste table 2, but it explicitly states Alternative: and, Primary && (same for or and ||).

So they are absolutely identical. If you want to try and convince yourself one is "better" than the other, that's your business. If someone else is trying to argue such, they'd better have a good reason.

Edit: The aforementioned Table 2:

Table 2 — Alternative tokens
Alternative Primary
<%          {
%>          }
<:          [
:>          ]
%:          #
%:%:        ##
and         &&
bitor       |
or          ||
xor         ˆ
compl       ~
bitand      &
and_eq      &=
or_eq       |=
xor_eq      ˆ=
not         !
not_eq      !=

Edit: Maybe worth noting, according to Sebastian Redl, MS break the rules here.

like image 142
BoBTFish Avatar answered Sep 19 '22 03:09

BoBTFish


I prefer && instead of and.

  • && is widely known and accepted, while many don't even know that and is valid C++.
  • Some IDEs don't accept and (and friends) by default. For example MSVC++.
  • At least for me, the operator precedence of && and || is ingrained into my head. While and and or have the same precedences as && and ||, the simple fact that I'm much less used to them makes it harder to read a condition.

On the other hand, and is more verbose and might be easier to use for programmers who have learned programming with languages that don't use &&. But one could argue that these people should learn C++ rather than try to change it's snytax.

like image 44
s3rius Avatar answered Sep 20 '22 03:09

s3rius