Will my compiler ignore useless code?

前端 未结 9 1301
情深已故
情深已故 2021-02-06 21:53

I\'ve been through a few questions over the network about this subject but I didn\'t find any answer for my question, or it\'s for another language or it doesn\'t answer totally

9条回答
  •  太阳男子
    2021-02-06 22:14

    Is (explicit or not) useless code ignored by the compiler?

    You can't easily determine it's useless, so the compiler can't either. The getter of TestRunTime.Length can have side-effects, for example.

    The background is that I maintain a lot of code (that I didn't write) and I was wondering if useless code should be a target

    Before you refactor a piece of code, you have to verify what it does in order to be able to change it and say afterwards it still has the same result. Unit tests are a great way of doing this.

提交回复
热议问题