c++ styleguide: why to have non-lvalues on the left side?

前端 未结 2 1230
执念已碎
执念已碎 2020-12-07 01:17

In one C++ coding style guide, I found one particular recommendation (page 41, recommendation number 53):

Always have non-lvalues on the left side (<

相关标签:
2条回答
  • 2020-12-07 02:07

    As you say, the reason some people use it is to occasionally avoid typing = when they mean ==.

    Since it only catches some cases, where you're comparing a lvalue with a constant or rvalue, and every compiler I know of will warn you if you make that mistake, there's very little point in doing it.

    At least to native English speakers, it makes the code read as if it's written backwards; so a "Yoda condition" some call it do. Like many rules in corporate style guides, it dates back to a time when dealing with unforgiving compilers was a higher priority than writing readable code.

    0 讨论(0)
  • 2020-12-07 02:12

    Yes, you guessed it right. It's the good, old Yoda condition!!!

    enter image description here

    0 讨论(0)
提交回复
热议问题