6 ms·
Static Analysis
- whitten 6y agoHow common in the industry is the use of 'invar' to signal an invariant, 'ensure' to signal a postcondition, and 'require' to signal a pre-condition ?
- rhencke 6y agoEiffel uses 'ensure' and 'require' for these meanings. .NET Code Contracts (may it rest in peace) uses 'Ensures' and 'Requires' for these meanings as well.
- whitten 6y agowhat about for invariants ?
- rhencke 6y agoEiffel uses 'invariant', and .NET Code Contracts uses 'Invariant'.
- skrebbel 6y agoassert() is pretty much the industry standard for invariants, right? they're usually evaluated at runtime but it should be perfectly possible for a static analysis tool to "evaluate" them statically.
- judofyr 6y agoassert() by itself is typically not the same as "defining an invariant". An invariant is an expression which should be true for the whole life-time of the block/function/program/anything, but assert() only defines an assertion at a specific point.
- nimmer 6y agoPlus, assert() is commonly used for runtime checks, not static analysis.
- rurban 6y agoYou can use static_assert but compilers observe assert already. assume is another commonly used invariant.
- Someone 6y ago“An invariant is an expression which should be true for the whole life-time of the block/function/program/anything” It should hold at both entry and exit of a block, but practically always doesn’t for the entire block.
- dhekir 6y agoACSL (https://en.wikipedia.org/wiki/ANSI/ISO_C_Specification_Language https://en.wikipedia.org/wiki/ANSI/ISO_C_Specification_Langu...) for C, which is based on JML (https://en.wikipedia.org/wiki/Java_Modeling_Language https://en.wikipedia.org/wiki/Java_Modeling_Language) for Java, both use 'requires' for preconditions, 'ensures' for postconditions, and 'invariant' for invariants. Some invariants are also written as assertions ('assert').
- Animats 6y agoThe real benefit of static analysis is non-local. It's automatically catching that A, which has some entry condition, is being called correctly by B, way over in another file maintained by someone else. This is why the borrow checker in Rust, which is a form of static analysis, is so valuable. It keeps you from global ambiguity over who owns what. Compare linters and style checkers, which merely enforce local no-nos. The value in the more elaborate tools is automatically catching errors where each piece of code looks fine in isolation. Proof of correctness work tends to focus on local issues, because that's the academic history. But that's not where it is really valuable.
- nimmer 6y ago> the borrow checker in Rust, which is a form of static analysis, is so valuable > Compare linters and style checkers Odd comparison: static analysis is way more powerful than these two examples. It can spot plenty of subtle bugs due to incorrect reasoning around a problem.
- Cyph0n 6y agoGenuinely curious: is static analysis really more powerful than the Rust type system + borrow checker? A more concrete example: is Coverity + C more powerful than Rust?
- thechao 6y agoThere’s no model more powerful than static analysis if, by static analysis, they mean abstract interpretation: the Galois connection guarantees this.
- throwgeorge 6y ago>Galois connection Lol man I've seen some funny things pulled out people's butts to sound smart but this takes the cake. Please do tell what is the connection between galois groups and static analysis.
- 6y ago
- mkchoi212 6y agoI can't understand how people use languages without static analysis. The only edge case I can think is using any scripting language to write a script that is less than 1k lines. Are there any pros for languages that don't have static analysis other than the fact that it allows "rapid development/prototyping"?
- nimmer 6y ago> Are there any pros for languages that don't have static analysis other than the fact that it allows "rapid development/prototyping"? Nim is similar to Python in syntax and speed of development and yet it supports static analysis. The difference is that is newer than Python, Ruby & co.
- ed25519FUUU 6y agoAnd, of course, a huge difference in number and quality of 3rd party libraries.
- deleted 6y ago[deleted]
- ievans 6y agoWhen they get big enough, they add the static analysis on top of the language to make it more robust. There's a good read by Instagram (all Python) on this: https://instagram-engineering.com/static-analysis-at-scale-an-instagram-story-8f498ab71a0c https://instagram-engineering.com/static-analysis-at-scale-a...
- beders 6y agoSo you don't know any successful projects in JavaScript, Clojure, Erlang, Elixir, Groovy, Julia, R, etc. etc. etc.? ;) There are well-known advantages and repeating them here will incite another flame-war. I can only speak from my 35 years of coding experience, spending most of that time in the confines of static typing: Most problems I solve today are not good fits for static types. They cause major headaches along the road as your customer's needs change and as I get a better understanding of the problem domain.
- themodelplumber 6y agoI have no good reason to know about "full formal chains," and yet attempting to read the article still managed to grind my programmer ego into the dirt. :) Major respect to people who operate in that world. Related to Nim in general: I'm excited to use Nim more. Prior to finding Nim, I had this list of languages to explore in more depth: Python, Ruby, Lisp, Pascal (though I still plan to explore those). Oh, and find a good scripting language, in addition to one from the compiled language group. Oh, and avoid anything too "enterprise". So if you know anything about Nim, you know why this feels pretty amazing.
- aEverr 6y agoWhat's wrong with "anything too enterprise"?
- themodelplumber 6y agoI used to deploy and support enterprise software, which I chose from a contingency point of view: More users, more important users, and thus a lesser chance of being "wrong" about the choice of software. I had some good experiences, some bad. Then I tried non-enterprise software. I picked out some lightweight tools and platforms and swore I'd drive them into the ground and get to the same goals, just to see what I could do without the enterprise overhead components. This experience practically changed my life--lightweight has been _the_ way to go for me ever since, whether by hook or by crook.
- elcritch 6y agoYou might consider Elixir for scripting / systems language as well. LiveView is lightweight but allows amazingly quick Web-dev. Nim incorporates some Pascal concepts too. There's also a nice package to write native functions for Elixir in Nim [1]. 1: https://github.com/wltsmrz/nimler https://github.com/wltsmrz/nimler
- saghm 6y ago> Python, Ruby, Lisp, Pascal (though I still plan to explore those). Oh, and find a good scripting language, in addition to one from the compiled language group It's interesting that you want to explore Python and Ruby more but seem to consider finding a good scripting language as a separate goal. They're both definitely scripting languages, so if you don't expect either to be good, why do you want to explore them more?
- compressedgas 6y agoLooks like Dafny https://www.microsoft.com/en-us/research/project/dafny-a-language-and-program-verifier-for-functional-correctness/ https://www.microsoft.com/en-us/research/project/dafny-a-lan...
- pietroppeter 6y agoNot yet released but the DrNim documentation is available online [1]. DrNim is the tool that will provide Static Analysis to Nim (based on z3). This will be probably presented in the upcoming Nim Online conference in June 20 [2]. [1] https://nim-lang.org/docs/drnim.html https://nim-lang.org/docs/drnim.html [2] https://forum.nim-lang.org/t/6418#39615 https://forum.nim-lang.org/t/6418#39615