4 ms·
Kinda curious - which languages panic on overflow?
by ars 13y ago
Kinda curious - which languages panic on overflow?
- pjmlp 13y agoAda, here is a small list of validations http://en.wikibooks.org/wiki/Ada_Programming/Pragmas/Suppress http://en.wikibooks.org/wiki/Ada_Programming/Pragmas/Suppres... Modula-2, a possible documentation link http://www.excelsior-usa.com/doc/xds/isom203.html#15 http://www.excelsior-usa.com/doc/xds/isom203.html#15 Just to cite two examples.
- weland 13y agoSo what happens when the Ada program runs into a failed compiler check? Does it: * Raise an exception? If so, it's up to the programmer to treat it correctly. There are various ways to detect overflows outside Ada; it's still up to the programmer to treat them correctly. Runtime detection of the overflow (in a hopelessly untested firmware of the Therac-25!) would have brought the matter no closer to resolution. * Abort execution? If so, is the behaviour of the program defined if execution is aborted? Because undefined behaviour from a control system is quite worse.
- jv2 13y agoNormally, raise an Exception; the outermost levels of the program should probably put the machine in a "safe" state if an exception is raised during operation e.g. turn off the radiation beam etc. I would have thought this is infinitely preferable to silently continuing after an error... SPARK Ada allows the use of source-code annotations to denote information flow in a program, and can vastly reduce the chances of these sorts of problems (at the expense of more programmer time). Standard Ada compilers can do a reasonable job of detecting some problems at compile-time, but SPARK seems to be the favoured method for safety-critical stuff.
- weland 13y ago> I would have thought this is infinitely preferable to silently continuing after an error... It definitely is! However, it still assumes that the exception is safely handled. The flaw in Therac 25's development process was that testing did not reveal this bug. Consequently, the error recovery process could have itself been incorrect and remain uncaught. It's tempting to think that, if error recovery is similar each time, testing it once is enough, but error recovery is as susceptible to being impeded by race conditions as any other part of the code. No uncertainty is removed this way. It's also worth noting that a value of 0 (to which the counter overflowed) was actually a legitimate value in the Therac-25 program.
- ars 13y agoAny chance of an example from a slightly more recent language? If you are going to say we shouldn't use C because of overflow handling, at least suggest a language that actually does it. Otherwise you haven't really made your case.
- pjmlp 13y agoAda is a recent language, just last year got a new standard revision. Chances are, when you travel by train or take a plane, the control system was developed in Ada. When human lives are at risk, C is becoming less and less an option. And when the company still goes C, many countries have certifications in place like MISRA, that make C look like Ada with C syntax.
- ars 13y agoFine, I'll grant you Ada, and it does seem like a good language for these kinds of things. But you have to acknowledge it's not going to become a popular language for regular software projects.
- pjmlp 13y agoSure I won't see the a SV startup using it.
- ArkyBeagle 13y agoLanguage choice is secondary to methodology, but Ada does a darn fine job of checking an awful lot of methodologically useful things up front. It's less the language than the ecosystem and the infrastructure. It's eminently possible to develop 'C' that's exhaustively tested - I've done it. I am not sure that is true of C++ or Java.