Double Negation in C++

后端 未结 14 2954
你的背包
你的背包 2020-11-22 10:40

I just came onto a project with a pretty huge code base.

I\'m mostly dealing with C++ and a lot of the code they write uses double negation for their boolean logic.

14条回答
  •  鱼传尺愫
    2020-11-22 11:00

    It's a technique to avoid writing (variable != 0) - i.e. to convert from whatever type it is to a bool.

    IMO Code like this has no place in systems that need to be maintained - because it is not immediately readable code (hence the question in the first place).

    Code must be legible - otherwise you leave a time debt legacy for the future - as it takes time to understand something that is needlessly convoluted.

提交回复
热议问题