3 ms·
I remember a discussion about a set of changes introducing a null check which was technically redundant and Linus criticizing said change for it. However, in my
by slaymaker1907 5y ago
I remember a discussion about a set of changes introducing a null check which was technically redundant and Linus criticizing said change for it. However, in my opinion redundant checks are often not a bad idea since while a check might be redundant now, software is ever changing and these "redundant" checks often help catch mistakes so long as they can be afforded from a performance perspective. I pretty much never view a check as redundant unless the check is in the same function or if it is in the same _small_ module.
Something I'd also really like to see more often in various systems is a better config for enabling/disabling various checks sort of like how log levels can be adjusted. i.e., checks divided into something like expensive, noticeable, and minor overhead as well as by software module so you could enable/disable all checks related to some particular subsystem without enabling expensive checks globally or having to individually enable each check.
Some people say if the check is worth doing at all, it should always be enabled, but I think that overlooks the reality that some checks can be useful but expensive. For an example of such a check, whenever I implement a custom data structure, I find it useful to have assertions before and after each operation checking that all conditions hold such as an order of elements being preserved. That check is O(n) though so you definitely don't want it running in production or even in most debug builds.