4 ms·
You would have a huge number of false positives, because if you're doing a bunch of null checking defensively you're going to be doing it redundantly a lot.
by rcxdude 5y ago
You would have a huge number of false positives, because if you're doing a bunch of null checking defensively you're going to be doing it redundantly a lot.
- IshKebab 5y agoRight, but if the compiler has proved that you don't need those null checks then you can simply remove them. If you think you do need them then it's a sign you've screwed up somewhere and should fix it!
- _flux 5y ago> Right, but if the compiler has proved that you don't need those null checks then you can simply remove them. This can be the case now, but then later someone adds new code that you did need that null check. > If you think you do need them then it's a sign you've screwed up somewhere and should fix it! Hm, so instead of > Wouldn't it be better to have compile errors if the compiler figures out that it can remove a null check? you wanted the opposite: warn when a null check is there and was actually required :). Not sure if this is a working solution either. Maybe if it was behind a macro, JUST_CHECKING_IF_NULL(x)..
- IshKebab 5y agoYeah sounds like the best solution is explicit checks that the compiler understands - REDUNDANT_NULL_CHECK(...), REQUIRED_NULL_CHECK(...). I mean obviously the solution is to use a sane language but you know...
- DSMan195276 5y agoThe problem is that it's not that simple. A NULL check might only become redundant after various rounds of inlining and optimizing, and the same NULL check could be redundant in one usage and necessary in the other. It's also very likely that changes to other parts of the code will make a previously 'redundant' NULL check now necessary, and obviously you're unlikely to get a warning in that direction.