4 ms·
> There is no 80/20 rule for C unsafety, Actually, there is; the problem is that the transpiler can't tell the difference between code that relies on unsafety
by a1369209993 4y ago
> There is no 80/20 rule for C unsafety,
Actually, there is; the problem is that the transpiler can't tell the difference between code that relies on unsafety for its semantics, versus code that would still work if appropiate annotations (potentially causing function to not be callable in intended contexts), run-time checks (possibly causing code to error out on what were intended to be valid inputs), etc, were added to make it safe.
80% of the code contains 20% of the cases where safety would require deviating from the intended semantics, not just the incidental ones. (A general-purpose transpiler can't (in general) tell the difference between intended semantics and incidental ones, so it has to conservatively assume all semantics are intended, and write everything as the most-general (ie most-unsafe) interpretation.)
- kazinator 4y agoAny C code that performs a calculation which would silently be wrong or crash if the values were not correct (even though they are) is inherently unsafe.
- turminal 4y agoThat's a weird way to put it. If your function assumes some constraints on the input it gets and you give it data that violates its constraints, it's going to fail in some way. Sure, C makes it worse by making it harder to verify the assumptions and constraints, but by your definition every function that operates on sorted arrays and doesn't verify the input is sorted is inherently unsafe, regardless of the language.
- jsjohnst 4y ago> but by your definition every function that operates on sorted arrays and doesn't verify the input is sorted is inherently unsafe Are you claiming it’s not? verify all input should be the baseline to call something safe imho.
- turminal 4y agoSure, but that's not a meaningful definition of safety, because according to this definition writing a safe O(log n) binary search is impossible in every single mainstream language in existence.