4 ms·
I never understood how is that different from decorating your function with `assert` statements. Is it analyzed statically ?
by agumonkey 6y ago
I never understood how is that different from decorating your function with `assert` statements. Is it analyzed statically ?
- Jtsummers 6y agoYes. SPARK/Ada will attempt to verify many of the properties statically. Not everything can be, and not everything can be done without significant effort (that is, more than it may be worth). But it's more than asserts in most other languages which are only verifiable dynamically. For those areas where SPARK can't prove something statically, the checks are used at runtime (like a traditional assert). It's a best of both worlds situation, in that regard.
- boibombeiro 6y agoYou can use formal verification tools to verify the code. Having preconditions ("assume" instead of "assert") reduces the search space.
- rramadass 6y agoasserts are just a language mechanism using which you implement preconditions/postconditions/invariants which are program correctness design constructs. Thus it is a systematic (i.e. not ad-hoc) way of using asserts correctly to guarantee program state. I highly recommend reading Bertrand Meyer's papers "Applying Design By Contract" and "Design by Contract". They are well worth every programmer's time.