3 ms·
A static check adds a way in which the programmer can mess up. A code path which fails a check was obviously not tested (at least, not since the change was int
by kazinator 10y ago
A static check adds a way in which the programmer can mess up.
A code path which fails a check was obviously not tested (at least, not since the change was introduced which triggers the check).
The programmer can massage the code so the check goes away, yet leave the code path still untested, due to the "safyness" feeling that that the machine "got his/her back", so all is well.
- AnimalMuppet 10y ago> A static check adds a way in which the programmer can mess up. True, though it is one that you can ignore. You can't ignore the compiler. Reading through the output of a static checker is 95% "Stupid hyper-picky static checker", and 5% "Oh #&%$@, we'd better fix that right away". Ignore the ones that should be ignored. > A code path which fails a check was obviously not tested (at least, not since the change was introduced which triggers the check). Or not tested with the right combination of inputs, or not tested looking for the right thing... > The programmer can massage the code so the check goes away, yet leave the code path still untested, due to the "safyness" feeling that that the machine "got his/her back", so all is well. Sure, they can, if they aren't trying to understand what the checker is telling them, and instead just try to get it to shut up. And they can do the same with a test.
- kazinator 10y ago> Or not tested with the right combination of inputs, or not tested looking for the right thing... There's the thing. Unless the code is exploiting dynamism, probing large input spaces is not required to catch the same issues. Just enough variety to achieve path coverage. We don't need to probe the space of integers to catch that a string operation is applied; running that expression with any value will do. I added a static check for uses of undefined functions and variables to a dynamic language quite recently. It didn't find anything in any of my application code. One instance was found in the language's standard library. The function which had that error was never tested. Calling that function with any argument at all triggered the dynamic check. The static check only pointed out this fact: hey, you didn't test this! That's a poor substitute for an actual path coverage tool. You can develop untested code which passes various static checks; only a coverage tool will show you the untested paths.
- Jweb_Guru 10y agoA coverage tool will not come remotely close to showing you untested paths. Array indexing, for example, is an implicit branch between every possible element in the array, but most coverage tools I've seen count just evaluating the indexing expression as covering the line. On the other hand, judicious use of indexed data types can guarantee a data path for all indices into the array. Simple sum types like Maybe and Either guarantee a data path for the more simple use cases of null or errors. Uses of undefined functions and variables are not what people are talking about here (though those do happen in dynamic languages); we're talking about stuff that can't be checked locally (like "is a null allowed to come into the function at all, and if it does are you covering it") that are hard or impossible to catch with coverage tools.
- kazinator 10y agoIf for some crazy reason we choose to regard an array access as if it were a big switch or case statement with a branch for each index, we are wrong in concluding that this creates a path coverage problem. These cases are machine-generated and do not require separate coverage treatment. An analogy might be found in, say, machine-unrolled loops. I don't care about coverage of multiple copies of a loop body caused by a compiler optimization.
- Jweb_Guru 10y agoHow do you know that each array index will succeed, without a proof (or type) to that effect? You don't. You're arguing from the technical definition of path coverage (cases that are machine-generated "don't count"), but I'm arguing from "actually covering the behavior of your program," which means they absolutely do. You're also assuming that the behavior on failure will always be a crash, which isn't even close to being the worst kind of failure from an array index that returns something unexpected.
- kazinator 10y agoI don't care about that within the scope of coverage testing. I am not laboring under any misconception that path coverage is correctness proof. Path coverage is not "coverage of the behavior of the program". My thesis is that path coverage will catch a type error, like a floating-point value being used as the array index, or a non-array being indexed. Programs have to be contrived to harbor a type error in spite of complete path coverage. Complete path coverage means this: every node of the program's graph has is visited at least once at run-time. At that visit, type is determined. This is similar to traversing the program graph statically and determining the type at each node. Regarding your last point, yes, I'm working under the assumption that we catch errors rather than behave unpredictably.