4 ms·
Adding to why static analysis tools are not used: 1. The false positives sometimes lead to ugly workarounds needed to quiet the message. 2. There's no standar
by WalterBright 9y ago
Adding to why static analysis tools are not used:
1. The false positives sometimes lead to ugly workarounds needed to quiet the message.
2. There's no standard, meaning different SA tools produce very different results, often contradictory.
A better approach is to improve the language. For example, the `(a < b < c)` is tripped by many static analyzers. In D, the grammar was changed so `a < b < c` is not valid. And the C/C++ committees should really deprecate `l` as a valid integer literal suffix :-)
- randomfool 9y ago3. The checks are skipped for all the code in third_party which you are using.
- sanxiyn 9y agoIn Rust, static analysis ("lint") is part of language and every lint can be disabled in per function and per module basis. So ugly workarounds are never required.
- candiodari 9y agoWhat happens when the style guide authors inevitably declare that no lint messages should be disabled, ever ?
- sanxiyn 9y agoWell, that's a self-inflicted damage, isn't it? You can move to another team with less brain damaged style guide authors.
- candiodari 9y agoStyle guides are usually per company or at least per department. Leaving them behind isn't usually in the cards without severe other consequences. I usually write a python program that doesn't complain about style violations, it just fixes them, like autopep8, but with much more stuff, like correctly capitalizing function names, variables, making strings consistent, making or taking away long-quotes, putting conditions in ifs, even renames shadowed variables (built it in last week after what feels like the 100th time I hit a bug due to shadowing) ... Makes people wonder how I can possibly program so fast under such onerous rules. On the downside: I work here now for 6+ years, and still don't know (or care) about most of the style guide, and frequently get confused when people ask questions "because you have written the most code, you must know, right ? Capitalize functions or not ? ... Ehm, well ...". Also, people ignore these things, so I must run it on any file I edit and submit a "style fixes" cl before doing anything else. But since git became an option, not much of a problem. That's the trouble with style guides: 95% of what they do COULD have been implemented in editors if we demanded that style guide authors weren't "architects" and policy-makers, but programmers that really know what they're doing. Very little they do requires a policy, it can just be described as a parse-tree-transform. Instead, they're just people who feel they can just push their opinion on a large group of people, just because it makes them feel a bit better. That they can't actually program a fix, but instead just create another problem, doesn't seem to bother any of them, ever. And we actually reward people for this. I don't get that. These people CREATE a problem, then somehow negotiate this style with a department, slowing everyone down for no good reason other than that they don't know how to do it automatically, and they usually actually get rewarded for providing a bad solution. Like they "introduce standards". Even just providing a style-guide-checker with a consistent interface (so IDE integration would be easy) is too much to ask at every place I've ever worked. No, they substitute 10% of the all labor in this company for the job a simple perl script COULD do.
- w8rbt 9y agoAnything that has a type system is using static analysis.
- ninjin 9y agoRegarding 1., not just ugly workarounds, remember how Debian broke their OpenSSL PRNG for several years to silence warnings for analysis tools [1] – read the impact section and shiver if you had not heard of this one before. There are real world risks associated with spurious warnings. [1]: https://github.com/g0tmi1k/debian-ssh https://github.com/g0tmi1k/debian-ssh
- jcranmer 9y agoWell, that's not quite an accurate representation of the issue. OpenSSL was trying to use uninitialized memory to seed the PRNG in one of the calls. The fix silenced the warnings by removing (almost) all seeding of the PRNG, instead of just the uninitialized memory seeding. To his credit, the patch author did attempt to ask the OpenSSL developers if the patch was doing things correctly. However, the developers apparently didn't watch their own mailing list, and this didn't come out until after the problems were made public and the developers were laughing about what a n00b the Debian contributor was.
- ninjin 9y agoI hate to misrepresent facts, but after looking over what I wrote and reading what I linked for the first time in many years I don’t see any misrepresentation of the issue. Yes, what you write adds additional detail, but nowhere do I or what I link go after the Debian contributor; I was simply trying to make the point that spurious errors can lead us astray. Thank you for adding more nuance and do correct me if I messed up somewhere as I am unable to see it myself.
- HALtheWise 9y agoThis sort of problem is probably why the article doesn't recommend compiler warnings as a useful intervention point: they can be ignored, but then continue to annoy future developers who aren't responsible for the mistake.
- taeric 9y agoI disagree that it is a better approach to improve the language. Rather, it is easier. At that point. It is harder in that it requires rewriting all of the projects you had. And it is wishful thinking to think you will not have regressions in either correctness or performance. Often both. Edit: to be explicit, I'm not saying it is worse, either. Just has trade offs.
- bluGill 9y ago1 is why I refuse to allow any static check in my company if you can show a real false positive in our code. If there is any doubt someone will quickly try to place all instances of that error in the doubt, and it is up to me (as the maintainer of static checks) to prove them wrong. I have never seen contradictory parts of 2, so I don't know what you are talking about. If it is what I think: I would reject one of the two tools just so that I had a single easy to apply set of rules that have no false positives. Static analysis is very valuable, but only when you can treat it like the hand of some god that will throw lightening at any developer who writes a found error. I'm currently looking at 1 suppression per 2 million lines of code. I think there is more value in more checks, but unless they can be fully automated without telling everybody how to suppress false positives I won't consider them.
- UncleMeat 9y agoYou don't allow any type checking? You can tune an analysis to be considerably more conservative and reduce false positives. The analysis becomes more like a semantically aware formatter. Doing most things related to pointers will lead to FPs, but you can still get value even if you are terrified of FPs.
- bluGill 9y agoWe do lots of checks. Most of our code is C++ where we get a fair amount "free", and the few times where type checks get in the way they are easy to bypass in a natural way.
- Eridrus 9y ago> 1 is why I refuse to allow any static check in my company if you can show a real false positive in our code. So no linters either?
- bluGill 9y agoWe have a couple linters. They all have a zero false positives policy. We have about 1 suppression per 2 million lines of code because of bugs in the linters we use - every one of the suppression was accepted as a bug by upstream before we suppressed it. I know that there are lots of checks that would be useful that we are missing. However they are not worth looking at because every false positive destroys some trust, and soon they are not trusted even when they are right.
- Klathmon 9y agoRe. #1 It sounds to me like the issue isn't that false positives exist (you aren't ever going to fully get rid of them), it's that the SA tools need easy "escape hatches" for those false positives. Even something as simple as an editor plugin to let you click on a specific "error" or "warning" and click "silence" to add a magic comment or something to explicitly "allow" the line/function/file. It reduces the amount of extra work from a false positive to next to nothing, it still can and will catch issues before they hit production, and it can make iffy-code more explicit (The added magic comment essentially saying "yes, i did mean to do that").
- namibj 9y agoThe PHP I write using Jetbrains IDE, with the most extensive static analysis plugin I could find, has that about 5 keystrokes away when you have the cursor on the sqiggly part. It's about the same keystrokes +-2 or so (navigation), to list all occurrences of that specific warning. So yes, what you ask for is already a thing in (more or less) standard tooling.
- WalterBright 9y ago1. The magic comments are specific to which analysis tool you're using, so don't work well with portable code. 2. Those magic comments are put in the source code, meaning they uglify the code in github, etc. Of course, one could create a separate database for the annotations, but that adds another layer of complexity for the users to prevent its use.
- Klathmon 9y agoI disagree. They are as portable as the code is, yes they might only work with a single language requiring another "format" for other linters in other languages, but they will stay with the code wherever it goes. And they aren't "uglifying" the code any more than type annotations or variable names. They are an additional hint to the user and the system about what a specific line or block of code is doing. They are just an annotation that the compiler ignores (for the most part).