Can you store a variable inside a if-clause?

后端 未结 6 1610
不思量自难忘°
不思量自难忘° 2021-01-01 16:21

I\'m kinda waiting for a \'no\' answer on this question.

I was interested if you can save a variable at the same time when you checking it in an if-clause.

6条回答
  •  甜味超标
    2021-01-01 16:51

    Three points that completely fail to answer the question:

    null is evil. Don't write methods that return it. Your example problem would then disappear.

    I think you might be missing out on encapsulation. Instead of foo.getBar() could the interface of foo be made such that you perform a "tell don't ask" operation?

    Side-effects in expression tends to cause bad code. Prefer more, simpler lines to fewer, buggy lines. The usual exception if using ++ to increment an index when accessing a buffer, or similar iterator style algorithms.

提交回复
热议问题