9 ms·
No, and to claim as much is simple laziness. It is possible to write provably correct code. Even if you don't want to go full formally verified, you can elimina
by lmm 11y ago
No, and to claim as much is simple laziness. It is possible to write provably correct code. Even if you don't want to go full formally verified, you can eliminate large categories of possible errors with a relatively small amount of proof.
None of which removes the need to write simple, understandable code without undocumented magic. But we should not be throwing up our hands and treating invalid accesses, memory safety failures, buffer overflows, SQL injection, XSS, or a whole host of common failures as inevitable. It really is possible to do a lot better than most programs and a lot better than C.
- Avshalom 11y agoright "the best we can do" is actually pretty damned good, if anyone would bother doing it.
- ozim 11y agoI bother doing it but it still ends up: "the best they want to pay us for" which usually is less than the best.
- bloaf 11y agoThat reminds me of the old G.K. Chesterton quote, which was originally about religion. Provable correctness "...has not been tried and found wanting; it has been found difficult and not tried."
- AnimalMuppet 11y agoWhat is the largest program that has been proven correct? We're writing programs that are tens of millions of lines of code (OSes, databases, air traffic control systems). My impression of provable correctness is that the largest program that has been proven is in the area of 100,000 lines (feel free to correct if I am in error). We need to be able to prove programs two orders of magnitude bigger than that; provable correctness has not been tried for such programs because nobody wants to wait a generation or two before they get the results.
- ArkyBeagle 11y agoSo maybe 1) we shouldn't wrote systems that are tens of millions of anarchically intercoupled lines of code or 2) we should write 100 100,000 line subsystems and link them together in a rigorous way. They key is then to simply avoid emergent interactions between modules/subsystems. That's pretty doable. What doesn't happen is that people never reason about the cost of defects. Even if they do some reasoning about this, they don't apply that to other components of systems.
- nickpsecurity 11y agoExactly what I said above. Verifying individual components and their straight-forward compisition is how it was done in the past. People just ignore that.
- ArkyBeagle 11y agoI heard you. I just still fail to believe it. :)
- jl6 11y agoY'know a lot of the best, most robust and mature software out there is a generation old... Maybe that's just how long it takes to get large scale software right.
- nickpsecurity 11y agoSort of. We haven't proven a single thing beyond certain size and complexity. That was true when it started back in Orange Book days. Even when Dijkstra came up with the stuff and the method of dealing witg it: composition w/ preconditions, postconditions, and invariants. You code in a functional style and/or with state machines composed. They composed stuff hierarchically and loopfree where possible to facilitate analysis. Each component is small enough to analyze for all success or failure states. The results of each become "verification conditions" for things that build on it. With such methods, one can build things that are as large as you want so long as each component (primitive or composite) can be analyzed. Not clear at what point this breaks down. I used it for drivers, protocols, algorithms, systems, networks, and so one. I brute forced it with more manual analysis because Im not mathematical or trained enough for proofs. However, what holds it back on large things is usually just lack of effort far as I can tell.
- lutusp 11y ago> It is possible to write provably correct code. How many modern programmers hold this mistaken belief? It's false -- the Turing Halting problem (https://en.wikipedia.org/wiki/Halting_problem https://en.wikipedia.org/wiki/Halting_problem) demonstrates that one cannot establish that a non-trivial program is "provably correct." It seems the OP got carried away with his rhetoric, and the way he put it is simply wrong.
- geofft 11y agoThat is a very common but incorrect misinterpretation of the halting problem. The halting problem says that there exist programs that cannot be proven correct; it says that for any property you want to prove computationally, no program can give you an answer for every last program. It doesn't say anything about "non-trivial" programs. In particular, if you write programs with awareness of the halting problem in mind, you can write extremely complicated programs that are provably correct. One straightforward way to do this is with a language that always halts. The proof assistant Coq is based on such a language, and it's powerful enough to write a C compiler: http://compcert.inria.fr/ http://compcert.inria.fr/ It is certainly correct that you can't stuff an arbitrarily vexatious program through a proof assistant and get anything useful on the other side. But nobody is interested in proving things about arbitrarily vexatious programs; they're interested in proving things about programs that cooperate with the proof process. If your program doesn't want to cooperate, you don't need an exact answer; you might as well just say "No, I don't care, I'm not trusting you."
- pekk 11y agoThat is an incorrect misinterpretation of the posts you are responding to. If a programming language is Turing complete, then there is no way to prove that programs in that language halt in the general case (undecidable). The general case is important. It is not reasonable for a compiler which claims to detect halting to just bug out and refuse to compile certain valid programs. At best, people might still run a linting program which detects halting sometimes, but that flakiness is no good for the compiler. One of the implications of the halting problem is that a language in which all valid programs halt is not Turing complete. If you mean to say that you think programming's future is languages that are not Turing complete, just say so and then you can avoid delivering these condescending lectures to people who are operating under the reasonable assumption that future programming languages of general usefulness will be Turing-complete just like almost all the successful languages of the past have been.
- kazinator 11y ago> It is possible to write provably correct code. ... and then someone finds a bug in the specification which is provably correctly implemented. Using gets() to read the input can be provably correct. All you have to do is remove any requirements for security from the program's specification, and specify that the program will always be used in circumstances when the expected input datum will be less than a certain length. ... and then the hardware is buggy or failing. That RAM bit flips and you're screwed. The machine as a whole isn't provably correct.
- Avshalom 11y agoCosmic rays are no excuse not to throw an exception on integer overflow.
- kazinator 11y agoIf, for some inputs, the program is supposed to calculate the value 42, but it throws an integer overflow, then it is not correct. Detecting overflows and throwing nice exceptions instead of continuing execution with garbage values isn't the same thing as ensuring correctness.
- ealloc 11y agoIs it really the case that some programming languages are more resilient to hardware errors than others? Java does array bounds checking in principle, but it is usually optimized out of the machine code. Isn't it then virtually just as susceptible to hardware error as C? And the JVM is written in C anyway.
- kazinator 11y agoThis has been the subject of some papers, like https://www.cs.princeton.edu/~appel/papers/memerr.pdf https://www.cs.princeton.edu/~appel/papers/memerr.pdf [2003]
- lmm 11y agoThe JVM is written in C, but that C has been subject to some formal analysis. And even if it hadn't, I'd bet the defect rate of a Java program running on a C JVM would be much much lower than that of a C program.
- rprospero 11y agoI interpreted the comment a bit more generously that you did. You're absolutely corrent that it's possible, and I'll go as far as to say even desireable, to write provable correct code. However, I've never seen a demonstration of probably correct hardware. I interpreted the comment as reminder that even binary is, ultimately, a leaky abstraction. I used to work in a facility where they'd test systems for radiation hardness. Get the system running, then shoot a proton beam travelling a significant fraction of the speed of light directly at the processor. It doesn't matter if the code was proven correct Dijkstra, it will eventually manifest bugs under these conditions.
- lmm 11y agoI don't think anyone proves their hardware from basic physics[1], but hardware comes with specs and tolerances. If your software needs to operate in a high-radiation environment, you buy appropriate hardware and potentially take other countermeasures (e.g. multiple processors executing in sync). [1] practically we resort to empirical testing to confirm that hardware conforms to its spec. But as your sibling says, that's no excuse not to do better in the places where we can.
- nickpsecurity 11y agoEAL7 data diodes with octocouplers and EMSEC do. Oh, snap, you didnt see that coming! :P
- sfk 11y agoPerhaps don't put your system in the path of a proton beam? I've had a large test suite that consistently used 8GB running for three years without ECC RAM. Any bit flip would have been caught by the test suite. My conclusion is that bit flips are entirely exaggerated (probably by the hardware industry for obvious reasons).
- effie 11y agoDo you have the suite published? The frequency of errors depends on how much memory and in which conditions it is being used. Datacenters, supercomputers, even personal workstations used for scientific calculations benefit from error correction. Check this out: http://techcrunch.com/2009/11/02/new-study-proves-that-ecc-memory-may-well-be-worth-the-extra-cost/ http://techcrunch.com/2009/11/02/new-study-proves-that-ecc-m...
- aidenn0 11y agoJohn Regehr observed a proven-correct C compiler generating incorrect code. The reason? An error in a system header file. The truth of the matter is that for most of the software systems formally proving every single piece of the system to be correct is too expensive. Perhaps as the rate of change in the software industry inevitably slows, this will change, as slower change will increase re-usability, but at the moment it is the sad state of things.
- mwfunk 11y agoThe discussion is about C, so I would assume the post you're responding to was in that scope as well. Leading with an insult isn't likely to win any hearts or minds either.
- taneq 11y agoAll you do by proving code correct is shift any errors from the code to the proof.