Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #41195 > unrolled thread
| Started by | Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> |
|---|---|
| First post | 2016-02-23 22:19 +0000 |
| Last post | 2016-02-24 06:22 -0800 |
| Articles | 20 on this page of 38 — 11 participants |
Back to article view | Back to comp.lang.c++
asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-23 22:19 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 11:27 +1300
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-23 22:32 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 11:44 +1300
Re: asserts considered harmful Cholo Lennon <chololennon@hotmail.com> - 2016-02-24 16:49 -0300
Re: asserts considered harmful "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-24 00:00 +0100
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-23 23:20 +0000
Re: asserts considered harmful "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-24 01:02 +0100
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 00:17 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 13:25 +1300
Re: asserts considered harmful Vir Campestris <vir.campestris@invalid.invalid> - 2016-02-24 21:27 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-25 10:59 +1300
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 14:13 -0800
Re: asserts considered harmful scott@slp53.sl.home (Scott Lurndal) - 2016-02-25 00:12 +0000
Re: asserts considered harmful David Brown <david.brown@hesbynett.no> - 2016-02-25 01:23 +0100
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-25 15:29 +1300
Re: asserts considered harmful Vir Campestris <vir.campestris@invalid.invalid> - 2016-02-25 23:05 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-26 19:41 +1300
Re: asserts considered harmful David Brown <david.brown@hesbynett.no> - 2016-02-26 17:11 +0100
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 17:32 -0800
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 13:00 +1300
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 00:24 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 13:34 +1300
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 01:21 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 14:55 +1300
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-23 18:47 -0800
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 17:52 +0000
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 11:14 -0800
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 19:42 +0000
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 12:58 -0800
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 21:49 +0000
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 14:03 -0800
Re: asserts considered harmful Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-24 11:48 +0200
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 23:14 +1300
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 05:52 -0800
Re: asserts considered harmful woodbrian77@gmail.com - 2016-03-09 11:32 -0800
Re: asserts considered harmful mark <mark@invalid.invalid> - 2016-02-24 14:43 +0100
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 06:22 -0800
Page 1 of 2 [1] 2 Next page →
| From | Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> |
|---|---|
| Date | 2016-02-23 22:19 +0000 |
| Subject | asserts considered harmful |
| Message-ID | <8_2dnQWwaKOXRlHLnZ2dnUU7-dudnZ2d@giganews.com> |
Code containing asserts will behave differently depending on whether or not the macro NDEBUG is defined. This is dangerous as it may result in undetected bugs in a release build manifesting as undefined behaviour that doesn't cause a straight crash but does something more serious. One should prefer exceptions to asserts. One should have many exception types and many throws (a throw statement should have no performance impact in a decent implementation for the code path where no exception is thrown) but few try/catches. I recommend having a top level try/catch in main() and a few other try/catches where appropriate (for exceptional cases that are recoverable without terminating the application). Remember: asserts considered harmful. /Flibble
[toc] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2016-02-24 11:27 +1300 |
| Message-ID | <dj44lnFj7j3U2@mid.individual.net> |
| In reply to | #41195 |
Mr Flibble wrote: > Code containing asserts will behave differently depending on whether or > not the macro NDEBUG is defined. This is dangerous as it may result in > undetected bugs in a release build manifesting as undefined behaviour > that doesn't cause a straight crash but does something more serious. So don't change NDEBUG in your release builds. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> |
|---|---|
| Date | 2016-02-23 22:32 +0000 |
| Message-ID | <QPmdnYANj5KLQ1HLnZ2dnUU7-QmdnZ2d@giganews.com> |
| In reply to | #41197 |
On 23/02/2016 22:27, Ian Collins wrote: > Mr Flibble wrote: >> Code containing asserts will behave differently depending on whether or >> not the macro NDEBUG is defined. This is dangerous as it may result in >> undetected bugs in a release build manifesting as undefined behaviour >> that doesn't cause a straight crash but does something more serious. > > So don't change NDEBUG in your release builds. You are assuming everyone does that: they don't. /Flibble
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2016-02-24 11:44 +1300 |
| Message-ID | <dj45m4Fj7j3U3@mid.individual.net> |
| In reply to | #41198 |
Mr Flibble wrote: > On 23/02/2016 22:27, Ian Collins wrote: >> Mr Flibble wrote: >>> Code containing asserts will behave differently depending on whether or >>> not the macro NDEBUG is defined. This is dangerous as it may result in >>> undetected bugs in a release build manifesting as undefined behaviour >>> that doesn't cause a straight crash but does something more serious. >> >> So don't change NDEBUG in your release builds. > > You are assuming everyone does that: they don't. I'm not assuming, I'm recommending. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Date | 2016-02-24 16:49 -0300 |
| Message-ID | <nal1gm$bpt$1@gioia.aioe.org> |
| In reply to | #41197 |
On 02/23/2016 07:27 PM, Ian Collins wrote: > Mr Flibble wrote: >> Code containing asserts will behave differently depending on whether or >> not the macro NDEBUG is defined. This is dangerous as it may result in >> undetected bugs in a release build manifesting as undefined behaviour >> that doesn't cause a straight crash but does something more serious. > > So don't change NDEBUG in your release builds. > Long time ago I had to deal with a nasty assert enabled in release builds. From time to time (very seldom) our application crashed in a production environment. The application used an internal dynamic library which in turns used a third party library. The latter had an assert for an unusual situation (a network packet not recognized). The author decided that instead of just ignoring the packet o logging it, he had to assert. It was a bad decision combined with asserts enabled by default in release build. assert (I'm talking about C assert) must be used carefully and IMHO must not be enabled in release. If you need to report unsusual situations use exceptions or create a new assert macro on top of C++ exceptions. In my personal case I'm using asserts for pre/post conditions (expects/ensures) in a similar way to thoses described here: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md (from the link see "State preconditions (if any)" and "State postconditions") My macros are build on top of C++ exceptions and can be enabled/disabled in release builds. Regards -- Cholo Lennon Bs.As. ARG
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Date | 2016-02-24 00:00 +0100 |
| Message-ID | <naio4b$9ic$1@dont-email.me> |
| In reply to | #41195 |
On 23.02.2016 23:19, Mr Flibble wrote: > Code containing asserts will behave differently depending on whether or > not the macro NDEBUG is defined. This is dangerous as it may result in > undetected bugs in a release build manifesting as undefined behaviour > that doesn't cause a straight crash but does something more serious. Well, you can define a wrapper that throws an exception in NDEBUG (a.k.a. “release”) mode, then preferably a “hard exception” that has maximum chances of propagating all the way up to `main`. The main problem with that, as I see it, is that cleanup via stack unwinding can be dangerous when an assertion has failed. But I think the chances favor attempted cleanup as typically less destructive, less costly to the user, than a simple crash or just continuing with UB, which can do all kinds of Very Bad Things™. Of course one might ask the user. That's what the robots in Asimov's novels failed to consider, to just ask those that they served, before going all out with xenocide of the galaxy and mind control of humans. Anyway, as bonus points such a wrapper can do away with the silly restriction that the `assert` argument must be of scalar type (in C++ it can be enough that it's convertible to `bool`); the wrapper can possibly include logging; and the wrapper can be `constexpr`, which unfortunately is not guaranteed for plain `assert`. See <url: https://github.com/alf-p-steinbach/cppx/blob/master/source_code/cppx/basics/execution/assertions/CPPX_ASSERT.hpp> for an example (does not include logging, nor asking, but is `constexpr`). > One should prefer exceptions to asserts. One should have many exception > types and many throws (a throw statement should have no performance > impact in a decent implementation for the code path where no exception > is thrown) but few try/catches. I think this is much like an argument that one should prefer runtime type checking, namely based on a conflation of issues, and designed to make one particular chosen approach to things seem preferable. An assertion expresses an INCORRECT ASSUMPTION, strongly associated with preconditions. This is a contract breach by a caller, or by preceding code, and it indicates something wrong up there, often with no way to be sure exactly where or what. Throwing an ordinary exception misinforms the calling code, which will handle the ordinary exception as if this code, not itself, had failed. An exception (a standard exception) throwing, OTOH., expresses a GOAL ACHIEVEMENT FAILURE, strongly associated with postconditions. This is a local failure. One knows what's wrong, e.g. some resource exhausted, some item not found, whatever, including the case where some lower level function failed, possibly via exception. And the design called for such failure to be communicated back up via an exception. > I recommend having a top level try/catch in main() and a few other > try/catches where appropriate (for exceptional cases that are > recoverable without terminating the application). Yes, I agree that's useful. In particular, otherwise a Windows GUI subsystem program can just silently terminate... And there's also the issue of stack unwinding not being guaranteed for an unhandled exception. > Remember: asserts considered harmful. No. :) Cheers!, - Alf
[toc] | [prev] | [next] | [standalone]
| From | Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> |
|---|---|
| Date | 2016-02-23 23:20 +0000 |
| Message-ID | <6a6dndcqc5TVdFHLnZ2dnUU7-eednZ2d@giganews.com> |
| In reply to | #41201 |
On 23/02/2016 23:00, Alf P. Steinbach wrote: > On 23.02.2016 23:19, Mr Flibble wrote: > >> One should prefer exceptions to asserts. One should have many exception >> types and many throws (a throw statement should have no performance >> impact in a decent implementation for the code path where no exception >> is thrown) but few try/catches. > > I think this is much like an argument that one should prefer runtime > type checking, namely based on a conflation of issues, and designed to > make one particular chosen approach to things seem preferable. > > An assertion expresses an INCORRECT ASSUMPTION, strongly associated with > preconditions. > > This is a contract breach by a caller, or by preceding code, and it > indicates something wrong up there, often with no way to be sure exactly > where or what. > > Throwing an ordinary exception misinforms the calling code, which will > handle the ordinary exception as if this code, not itself, had failed. > > An exception (a standard exception) throwing, OTOH., expresses a GOAL > ACHIEVEMENT FAILURE, strongly associated with postconditions. > > This is a local failure. One knows what's wrong, e.g. some resource > exhausted, some item not found, whatever, including the case where some > lower level function failed, possibly via exception. And the design > called for such failure to be communicated back up via an exception. Not true: std::logic_error is meant for coding errors including incorrect assumptions. One should derive custom exceptions from std::logic_error and throw these instead of asserting. /Flibble
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Date | 2016-02-24 01:02 +0100 |
| Message-ID | <nairpf$p3c$1@dont-email.me> |
| In reply to | #41202 |
On 24.02.2016 00:20, Mr Flibble wrote: > On 23/02/2016 23:00, Alf P. Steinbach wrote: >> On 23.02.2016 23:19, Mr Flibble wrote: >> >>> One should prefer exceptions to asserts. One should have many exception >>> types and many throws (a throw statement should have no performance >>> impact in a decent implementation for the code path where no exception >>> is thrown) but few try/catches. >> >> I think this is much like an argument that one should prefer runtime >> type checking, namely based on a conflation of issues, and designed to >> make one particular chosen approach to things seem preferable. >> >> An assertion expresses an INCORRECT ASSUMPTION, strongly associated with >> preconditions. >> >> This is a contract breach by a caller, or by preceding code, and it >> indicates something wrong up there, often with no way to be sure exactly >> where or what. >> >> Throwing an ordinary exception misinforms the calling code, which will >> handle the ordinary exception as if this code, not itself, had failed. >> >> An exception (a standard exception) throwing, OTOH., expresses a GOAL >> ACHIEVEMENT FAILURE, strongly associated with postconditions. >> >> This is a local failure. One knows what's wrong, e.g. some resource >> exhausted, some item not found, whatever, including the case where some >> lower level function failed, possibly via exception. And the design >> called for such failure to be communicated back up via an exception. > > Not true: std::logic_error is meant for coding errors including > incorrect assumptions. One should derive custom exceptions from > std::logic_error and throw these instead of asserting. Well, it's certainly true that SOMEONE once meant you to use `std::logic_error` in that way, otherwise it wouldn't be there. Counting against that, when thrown from deep down in a call chain `std::logic_error` is almost guaranteed to be caught by a general `std::exception` handler, and this code will treat it as a failure by the throwing code – instead of as indicating its own failure. So it's almost sure to be handled in the Wrong Way™. I consider this, about very concrete advantages/disadvantages, to be much more important for my use/don't use decision than the SOMEONE's opinion somewhere pre 1998. Are there other indications, beside `std::logic_error`, that the standard exception hierarchy & machinery is not at all well designed? Yes, for example that these critical exceptions can do dynamic allocation. And for example, that the semantics of `throw` exception specifications were never implemented by Microsoft and were deprecated in C++11. Oh, and `std::uncaught_exception`. Not to mention the extreme shenanigans one must go to, complex and inefficient, with internal re-throwing and catching, to extract full exception information with C++11 and later's nested exceptions. Well, and more. So, regarding what to use, I don't assign much weight to the SOMEONE's authority. ;-) - Alf
[toc] | [prev] | [next] | [standalone]
| From | Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> |
|---|---|
| Date | 2016-02-24 00:17 +0000 |
| Message-ID | <TPydnbBup_APa1HLnZ2dnUU7-KWdnZ2d@giganews.com> |
| In reply to | #41204 |
On 24/02/2016 00:02, Alf P. Steinbach wrote: > On 24.02.2016 00:20, Mr Flibble wrote: >> On 23/02/2016 23:00, Alf P. Steinbach wrote: >>> On 23.02.2016 23:19, Mr Flibble wrote: >>> >>>> One should prefer exceptions to asserts. One should have many >>>> exception >>>> types and many throws (a throw statement should have no performance >>>> impact in a decent implementation for the code path where no exception >>>> is thrown) but few try/catches. >>> >>> I think this is much like an argument that one should prefer runtime >>> type checking, namely based on a conflation of issues, and designed to >>> make one particular chosen approach to things seem preferable. >>> >>> An assertion expresses an INCORRECT ASSUMPTION, strongly associated with >>> preconditions. >>> >>> This is a contract breach by a caller, or by preceding code, and it >>> indicates something wrong up there, often with no way to be sure exactly >>> where or what. >>> >>> Throwing an ordinary exception misinforms the calling code, which will >>> handle the ordinary exception as if this code, not itself, had failed. >>> >>> An exception (a standard exception) throwing, OTOH., expresses a GOAL >>> ACHIEVEMENT FAILURE, strongly associated with postconditions. >>> >>> This is a local failure. One knows what's wrong, e.g. some resource >>> exhausted, some item not found, whatever, including the case where some >>> lower level function failed, possibly via exception. And the design >>> called for such failure to be communicated back up via an exception. >> >> Not true: std::logic_error is meant for coding errors including >> incorrect assumptions. One should derive custom exceptions from >> std::logic_error and throw these instead of asserting. > > Well, it's certainly true that SOMEONE once meant you to use > `std::logic_error` in that way, otherwise it wouldn't be there. > > Counting against that, when thrown from deep down in a call chain > `std::logic_error` is almost guaranteed to be caught by a general > `std::exception` handler, and this code will treat it as a failure by > the throwing code – instead of as indicating its own failure. So it's > almost sure to be handled in the Wrong Way™. I consider this, about very > concrete advantages/disadvantages, to be much more important for my > use/don't use decision than the SOMEONE's opinion somewhere pre 1998. std::logic_error exceptions can be caught, logged and re-thrown (terminating application) which is the only acceptable course of action: logic errors are non-recoverable; if one has been detected something is seriously amiss and to try to carry on regardless would be extremely unwise. Education is necessary to ensure this is done by the coder: just because some people might be handling it incorrectly doesn't mean it is unsound advice to follow especially for new non-legacy code. /Flibble
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2016-02-24 13:25 +1300 |
| Message-ID | <dj4bkkFj7j3U5@mid.individual.net> |
| In reply to | #41205 |
Mr Flibble wrote: > > std::logic_error exceptions can be caught, logged and re-thrown > (terminating application) which is the only acceptable course of action: > logic errors are non-recoverable; if one has been detected something is > seriously amiss and to try to carry on regardless would be extremely > unwise. Education is necessary to ensure this is done by the coder: > just because some people might be handling it incorrectly doesn't mean > it is unsound advice to follow especially for new non-legacy code. Unless you control all of the code, how can you grantee that there isn't a catch or std::exception somewhere in the call frame between your throw and catch of std::logic_error? If (and that is a big if) you are going to use an exception rather than an assert, it should be something outside of the standard exception hierarchy. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| Date | 2016-02-24 21:27 +0000 |
| Message-ID | <P9SdnZ8hitjVvVPLnZ2dnUU78cmdnZ2d@brightview.co.uk> |
| In reply to | #41202 |
On 23/02/2016 23:20, Mr Flibble wrote: > Not true: std::logic_error is meant for coding errors including > incorrect assumptions. One should derive custom exceptions from > std::logic_error and throw these instead of asserting. That doesn't mean assert is bad. Assert in debug builds can cause your program to blow up with a nice dump that's easy for you to sort out - the program has made no attempt to clean up before reporting the problem. But when the code is out in the field - imagine a word processor. The use has been typing for an hour, and hasn't saved. He inserts some funny field, the program asserts, and he loses his edits. Or the program doesn't assert, does its best to recover the error, forgets how it got in that situation - but there's at least a chance of saving the document. Also enough asserts will be big and slow. Just as I turn on the optimiser in the compiler before release, I disable lots of debug logging - and asserts. Andy
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2016-02-25 10:59 +1300 |
| Message-ID | <dj6nekFj7j3U11@mid.individual.net> |
| In reply to | #41230 |
Vir Campestris wrote: > On 23/02/2016 23:20, Mr Flibble wrote: >> Not true: std::logic_error is meant for coding errors including >> incorrect assumptions. One should derive custom exceptions from >> std::logic_error and throw these instead of asserting. > > That doesn't mean assert is bad. > > Assert in debug builds can cause your program to blow up with a nice > dump that's easy for you to sort out - the program has made no attempt > to clean up before reporting the problem. > > But when the code is out in the field - imagine a word processor. The > use has been typing for an hour, and hasn't saved. He inserts some funny > field, the program asserts, and he loses his edits. Or the program > doesn't assert, does its best to recover the error, forgets how it got > in that situation - but there's at least a chance of saving the document. > > Also enough asserts will be big and slow. Just as I turn on the > optimiser in the compiler before release, I disable lots of debug > logging - and asserts. A reasonable counter example to your word processor is a compiler. If the code generator hits an "impossible" condition it can't handle, bailing is the only option. Even your word processor, if it realised its internal state was corrupt, would have little choice but to abort. To do anything else would be courting disaster. The key point Flibble either doesn't get (or more likely, chooses to ignore) is asserts really should be used for exceptional conditions *from which there is no recovery*. In those situations you (as a developer) need as much information about the state of the application as you can get, hence aborting with a core dump or (as on OSX) an opportunity for the user to send a crash report. These asserts should never be removed from the code. Throwing an exception when you know something (possibly the stack) is corrupt is madness. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2016-02-24 14:13 -0800 |
| Message-ID | <2767e6c3-449d-4370-abc2-52556c35493a@googlegroups.com> |
| In reply to | #41230 |
On Wednesday, 24 February 2016 23:27:53 UTC+2, Vir Campestris wrote: > > But when the code is out in the field - imagine a word processor. The > use has been typing for an hour, and hasn't saved. He inserts some funny > field, the program asserts, and he loses his edits. Or the program > doesn't assert, does its best to recover the error, forgets how it got > in that situation - but there's at least a chance of saving the document. Aborting in unexpected state is likely safest choice for any serious software. Most word processors on market keep documents saved all time. Try. Turn computer's power off and on then run the word processor again. Majority of those tell that document was recovered (or couple of documents). If you really have one that does not do that then uninstall it and download LibreOffice or something. Avoiding aborting program on case of error makes sense on case of entertainment software because little defect in art or something can keep it enjoyable but a crash seriously annoys.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2016-02-25 00:12 +0000 |
| Message-ID | <tFrzy.2630$_f2.721@fx20.iad> |
| In reply to | #41234 |
=?ISO-8859-1?Q?=D6=F6_Tiib?= <ootiib@hot.ee> writes: >On Wednesday, 24 February 2016 23:27:53 UTC+2, Vir Campestris wrote: >> >> But when the code is out in the field - imagine a word processor. The >> use has been typing for an hour, and hasn't saved. He inserts some funny >> field, the program asserts, and he loses his edits. Or the program >> doesn't assert, does its best to recover the error, forgets how it got >> in that situation - but there's at least a chance of saving the document. > >Aborting in unexpected state is likely safest choice for any serious >software. Most serious software (e.g. safety critical or life critical) cannot _abort_ in unexpected state. It needs to fail safe, which isn't just calling 'assert'. We allow static_assert for compile-time invariants, but never asserts at runtime for any reason.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2016-02-25 01:23 +0100 |
| Message-ID | <nalhcd$s37$1@dont-email.me> |
| In reply to | #41236 |
On 25/02/16 01:12, Scott Lurndal wrote: > =?ISO-8859-1?Q?=D6=F6_Tiib?= <ootiib@hot.ee> writes: >> On Wednesday, 24 February 2016 23:27:53 UTC+2, Vir Campestris wrote: >>> >>> But when the code is out in the field - imagine a word processor. The >>> use has been typing for an hour, and hasn't saved. He inserts some funny >>> field, the program asserts, and he loses his edits. Or the program >>> doesn't assert, does its best to recover the error, forgets how it got >>> in that situation - but there's at least a chance of saving the document. >> >> Aborting in unexpected state is likely safest choice for any serious >> software. > > Most serious software (e.g. safety critical or life critical) cannot _abort_ > in unexpected state. It needs to fail safe, which isn't just calling 'assert'. > > We allow static_assert for compile-time invariants, but never asserts at > runtime for any reason. > That would depend on what you mean by "abort". For some safety systems, an "abort" that immediately disabled all outputs then hangs the processor could be the ideal fail-safe behaviour. Or perhaps "abort" could be used to force the hardware to restart with a minimal fail-safe firmware image. You are free to implement "abort" in whatever way makes sense for the system in question.
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2016-02-25 15:29 +1300 |
| Message-ID | <dj778qFj7j3U12@mid.individual.net> |
| In reply to | #41237 |
David Brown wrote: > On 25/02/16 01:12, Scott Lurndal wrote: >> =?ISO-8859-1?Q?=D6=F6_Tiib?= <ootiib@hot.ee> writes: >>> On Wednesday, 24 February 2016 23:27:53 UTC+2, Vir Campestris wrote: >>>> >>>> But when the code is out in the field - imagine a word processor. The >>>> use has been typing for an hour, and hasn't saved. He inserts some funny >>>> field, the program asserts, and he loses his edits. Or the program >>>> doesn't assert, does its best to recover the error, forgets how it got >>>> in that situation - but there's at least a chance of saving the document. >>> >>> Aborting in unexpected state is likely safest choice for any serious >>> software. >> >> Most serious software (e.g. safety critical or life critical) cannot _abort_ >> in unexpected state. It needs to fail safe, which isn't just calling 'assert'. >> >> We allow static_assert for compile-time invariants, but never asserts at >> runtime for any reason. >> > > That would depend on what you mean by "abort". For some safety systems, > an "abort" that immediately disabled all outputs then hangs the > processor could be the ideal fail-safe behaviour. Or perhaps "abort" > could be used to force the hardware to restart with a minimal fail-safe > firmware image. You are free to implement "abort" in whatever way makes > sense for the system in question. Those were certainly considerations for the last few control systems I worked on. The last was a propulsion and helm control system where a dead stop, painful as it could be, was better than destroying an engine or ramming a jetty at 40 knots! An earlier example was a telco power system controller, again, aborting (via assert) and falling back to hardware defaults was better than allowing outputs that could fry millions of dollars of kit. As you say, the result of a "abort" will vary from system to system but in all cases it must happen immediately when a problem is detected, not after some potentially catastrophic attempts at clean up. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| Date | 2016-02-25 23:05 +0000 |
| Message-ID | <XM2dnSFKqb4lFVLLnZ2dnUU78d-dnZ2d@brightview.co.uk> |
| In reply to | #41240 |
On 25/02/2016 02:29, Ian Collins wrote: > The last was a propulsion and helm control system where a dead stop, > painful as it could be, was better than destroying an engine or ramming > a jetty at 40 knots! I'll assume your stuff was pretty good, but... if you're on a destroyer approaching harbour at 40kts, and the engine management throws a wobbly you are in deep doodoo - because it's the brakes as well. There's no such thing as a dead stop on water. The big tankers take _miles_ to stop or turn even when everything is working. Andy
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2016-02-26 19:41 +1300 |
| Message-ID | <djaachFb0naU1@mid.individual.net> |
| In reply to | #41242 |
Vir Campestris wrote: > On 25/02/2016 02:29, Ian Collins wrote: >> The last was a propulsion and helm control system where a dead stop, >> painful as it could be, was better than destroying an engine or ramming >> a jetty at 40 knots! > > I'll assume your stuff was pretty good, but... if you're on a destroyer > approaching harbour at 40kts, and the engine management throws a wobbly > you are in deep doodoo - because it's the brakes as well. There's no > such thing as a dead stop on water. A jet boat dropping its reversing buckets comes pretty close! -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2016-02-26 17:11 +0100 |
| Message-ID | <napt9m$1us$2@dont-email.me> |
| In reply to | #41242 |
On 26/02/16 00:05, Vir Campestris wrote: > On 25/02/2016 02:29, Ian Collins wrote: >> The last was a propulsion and helm control system where a dead stop, >> painful as it could be, was better than destroying an engine or ramming >> a jetty at 40 knots! > > I'll assume your stuff was pretty good, but... if you're on a destroyer > approaching harbour at 40kts, and the engine management throws a wobbly > you are in deep doodoo - because it's the brakes as well. There's no > such thing as a dead stop on water. > > The big tankers take _miles_ to stop or turn even when everything is > working. > I think it is a fair assumption that Ian knew such details when making the software - or at least the customer who specified "if there is a serious problem, turn off all outputs" knew about them.
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2016-02-24 17:32 -0800 |
| Message-ID | <6074b543-b269-4d35-adca-abf07ec9c56e@googlegroups.com> |
| In reply to | #41236 |
On Thursday, 25 February 2016 02:12:18 UTC+2, Scott Lurndal wrote: > =?ISO-8859-1?Q?=D6=F6_Tiib?= <ootiib@hot.ee> writes: > >On Wednesday, 24 February 2016 23:27:53 UTC+2, Vir Campestris wrote: > >> > >> But when the code is out in the field - imagine a word processor. The > >> use has been typing for an hour, and hasn't saved. He inserts some funny > >> field, the program asserts, and he loses his edits. Or the program > >> doesn't assert, does its best to recover the error, forgets how it got > >> in that situation - but there's at least a chance of saving the document. > > > >Aborting in unexpected state is likely safest choice for any serious > >software. > > Most serious software (e.g. safety critical or life critical) cannot _abort_ > in unexpected state. It needs to fail safe, which isn't just calling 'assert'. If there are some special ways to do suicide quicker than with abort then indeed do it but don't attempt to repair anything. Don't forget the software just detected that it is insane. Somewhat safety critical system can be such that one process is "running" and other is waiting as "backup". If "running" process aborts then the "backup" takes over becomes "running" (and new "backup" is prepared). That is typically used when downtime of a service must be minimal. Somewhat better safety critical is to run 3 systems in parallel. Design software of each separately by different team. If one will give different output from other two then trust the majority kill the idiot and let 4th system (from 4th team) to take over. That is typically worth it when life of people can be on stake. > > We allow static_assert for compile-time invariants, but never asserts at > runtime for any reason. Never try to fix any insanity run-time, it is simply impossible. The defect did slip in and no test did detect it before so running mad software can no way deal with it. It can only suicide fast to give control over to more sane powers.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c++
csiph-web