Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

banta's blog

By banta, history, 5 years ago, In English

I have been using 'and' for '&&' and 'or' for '||' recently and they seem to work just as good as the symbols. And they are also faster to type for me and i feel it makes the code more readable.

Is there any difference between them?

Is to recommended to use && and ||, if yes why?

Why don't top coders use them?

  • Vote: I like it
  • -4
  • Vote: I do not like it

»
5 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

In fact there is no difference. 'and' and 'or' were added to c++, because at that time there were some non-QWERTY keyboards and symbols '&', '|' were missing in that keyboards. But now you can rarely see someone using it. I think there is just no need to use them, because now in every keyboard you can type '&' and '|', and in my opinion it is easier to type '&&' than 'and'.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Probably the best answer is that... this form has always been more popular among programmers (not only in c++ but generally) so new programmers get used to it and it still remains the most popular. People see others' codes and copy the solutions which they observe. But if we compare two forms I think && is better than and. Slightly but it is.

1) Suppose there are two expressions: (variableOne and variableTwo), (variableOne && variableTwo). In my opinion the second expression is more obvious because character & is rarely used in variables' names so it stands out against them. Possibly it's only the matter of habit but I see the difference in the clearness of above expressions. The first one is like: text-text-text and the second one is like: text- another character -text.

2) There a lot of operators. (), [], ::, ., ->, ++, --, -, +, *, &, /, %, <<, >>, <, <=, >=, ==, >, !=, ^ — they're operators too. And don't forget that some operators have their bit versions. 'and', 'or' are short words. But we cannot give such short names to all of the operators. Wouldn't it be strange if we use 'and' instead of && but still use normal < ? Both of them are operators. It's quite coherent if we use special characters to all of the operators (to be honest — most)

I don't think there is any experienced programmer who think 'and' is more obvious than &&.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    thaks for explaining so basically its a matter of choice, and it doesnt matter if I prefer 'and', 'or' and I use them in my code. so I can stick to these if I want and they wont cause any problems

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Yes it's ok.