Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c++ Is assert evil?

Name: Anonymous 2011-02-07 23:41

The Go language creators write*:

Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting. Proper error handling means that servers continue operation after non-fatal errors instead of crashing. Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code.

Surely they're being faggots, right?

______________________________
* http://golang.org/doc/go_faq.html

Name: Anonymous 2011-02-08 17:34

There's nothing wrong with using assert.

If you're writing a complete software application and don't have any facilities for third party plugins, or aren't writing a plugin/component for another system, then you have no reason to recover from application errors--any errors you didn't foresee are your own fault, and the program is already fucked, you might as well just abort and have the user restart it.

Exception handling is quite useful, but it shouldn't be used to recover from your own fucking errors. It should be used to recover from exceptional system conditions, like maybe your application doesn't have correct security permission to access a particular file. Or it should be used to notify other components of exceptional conditions if you're writing a driver/component/etc. for some other system. Keep in mind that exception handling has a fair amount of overhead as it increases code bloat and thus instruction cache misses. In C++, turning exception handling off at the compiler level (-fno-except in GCC), can cut your binary size down by as much as 15%-20%.

Most game developers don't use exception handling, at least not on consoles, instead they use a lot of asserts as they're developing something they have full control over.

Read this: http://gamesfromwithin.com/asserting-oneself

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List