Hacker News new | ask | show | jobs
by iamwil 3 days ago
It is a gap, but the spec is often declarative, on what needs to be true, rather than imperative, about all the exact steps. Hence, less prone to error. You're right that it proves the protocol, but not necessarily the implementation.

A not-quite-there way to close the gap is that you can generate traces from the spec/proof, a sequence of states and events that must hold true. and then you can use that trace to replay back in tests, and if the implementation is correct, then it should mirror the trace.

4 comments

I am the Truss author. In Truss, the proof associated with a program explicitly proves it meets the contract. You're right the contract is declarative, and the proof is what proves the compliance of the imperative code to the contract.
The spec is also nice in that higher level abstractions check they're using the lower level ones according to actual specified behaviour not intended behaviour.

E.g. with a normal programming language a bug in the hash-map internals that rarely returns the wrong element is undectable. With a spec, if the spec says it can ever return the wrong element, I'm going to run head first into that when I try and prove that my pathfinding algorithm using that hashmap for memoization is correct.

I don’t need to specify all steps, you need to know what correct means in your system. Then you find the steps to get there. The spec for a sorting algorithm says that the output is a permutation and that no element at I > J is smaller than the element at J. This is true for any sorting algorithm no matter the steps ie quick sort merge sort will have different steps but same spec
> spec is often declarative

ppl always come with weird workarounds to put in loops and if conditions and then throw it all away to use a general purpose programming languge

Maybe try not doing that?