3 ms·
One size does not fit all. Any debugging safety net will have a cost in terms of performance, and you usually have to pay that cost regardless of whether your c
by ryandrake 9y ago
One size does not fit all. Any debugging safety net will have a cost in terms of performance, and you usually have to pay that cost regardless of whether your code has bugs. It's why we don't release debug builds to customers or use them in production.
If it is vital to your application to detect a certain kind of bug in production, then turn the checking on in production and pay the cost. Maybe it is not vital to my application or my application does not have these bugs. In my case it would be needless to pay the cost.
To me, essential to delivering a good product is detecting and killing defective code before delivery. I recognize however, that this attitude is becoming more and more old fashioned.
- Aaargh20318 9y ago> To me, essential to delivering a good product is detecting and killing defective code before delivery. The problem is that you cannot prove the non-existence of bugs, even if you formally verify all your code, you've only proven that it conforms to spec, not that the spec is flawless. This is why you should always code defensively. Assume all code is buggy and take steps to deal with that. Code is written by humans, and humans make mistakes. That doesn't mean that you shouldn't try to deliver a flawless product, only that you should acknowledge the fact that you're going to fail.
- eru 9y agoYour argument would be in favour of a defensive spec, not in favour of a defensive implementation. To explain: your spec will have a few hygiene clauses like 'no stack overflow' or 'no crashes' and some things about what useful things the program should actually do. The latter is hard to formalise and deserve defense in depth. Lots of the former are easy to formalise and you can rely on the compiler to get it right. And that's what we are doing already anyway: even in C we just trust that a loop will compile to the appropriate conditional jumps and don't add defensive measures to check that.
- Aaargh20318 9y agoThe point is that you're not going to do formal verification of your software. There is actually very little formally verified software out there, and the verified code that does exist is relatively small. And no, you can't rely on the compiler to get it right. Maybe if you only write Haskell you can get there 99% but there will always be human errors in code that the compiler can't find.
- eru 9y agoWe rely on computers to get parts of our spec right all the time. Yes, a higher level language lets you offload more to the computer (like Haskell), but even in C we are doing some off that. Yes, in practice you seldom have much of a formal spec, agreed.
- geofft 9y ago> One size does not fit all. Any debugging safety net will have a cost in terms of performance, and you usually have to pay that cost regardless of whether your code has bugs. It's why we don't release debug builds to customers or use them in production. You should benchmark this. It is not true in the general case that any safety net will certainly have a cost. Here is a really good example of someone actually enabling checked arithmetic in production, benchmarking, and finding no measurable change in performance: https://www.reddit.com/r/rust/comments/2nlis8/which_classes_of_errors_remain_with_rust/cmeqh47/?context=2 https://www.reddit.com/r/rust/comments/2nlis8/which_classes_... Given that memory access is much slower than an integer comparison within the CPU, it's entirely possible that a bounds check can have zero performance impact, if it runs while the memory is being fetched, and your code is generally correct (i.e., does not cause the bounds check to raise an exception most of the time). Premature optimization is the root of all evil. (And if you're really interested in performance at the expense of security, consider running a unikernel: a lot of people run environments where there's essentially a single user on the box, and therefore no effective privsep. So why mess with copying things between userspace and kernelspace, enabling hardware protected memory, etc. when you don't need to?)