Блог пользователя banta

Автор banta, история, 6 лет назад, По-английски

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?

  • Проголосовать: нравится
  • -4
  • Проголосовать: не нравится

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

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'.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 &&.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    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

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Yes it's ok.