I don't like this… Is this cheating the language?

前端 未结 15 2660
一向
一向 2021-02-13 15:52

I have seen something like the following a couple times... and I hate it. Is this basically \'cheating\' the language? Or.. would you consider this to be \'ok\' because the IsNu

相关标签:
15条回答
  • 2021-02-13 16:34

    You're taking advantage of a language feature known as short circuiting. This is not cheating the language but in fact using a feature exactly how it was designed to be used.

    0 讨论(0)
  • 2021-02-13 16:34

    Relying on short-circuiting is the "right thing" to do in most cases. It leads to terser code with fewer moving parts. Which generally means easier to maintain. This is especially true in C and C++.

    I would seriously reconsider hiring someone who is not familiar with (and does not know how to use) short-circuiting operations.

    0 讨论(0)
  • 2021-02-13 16:38

    Writing code cost a lot of $ to a company. But maintaining it cost more !

    So, I'm OK with your point : chance are that this line of code will not be understood immediatly by the guy who will have to read it and correct it in 2 years.

    Of course, he will be asked to correct a critical production bug. He will search here and there and may not notice this.

    We should always code for the next guy and he may be less clever that we are. To me, this is the only thing to remember.

    And this implies that we use evident language features and avoid the others.

    All the best, Sylvain.

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