Assertion (computing) - Disabling Assertions

Disabling Assertions

Most languages allow assertions to be enabled or disabled globally, and sometimes independently. Assertions are often enabled during development and disabled during final testing and on release to the customer. Not checking assertions avoids the cost of evaluating the assertions while, assuming the assertions are free of side effects, still producing the same result under normal conditions. Under abnormal conditions, disabling assertion checking can mean that a program that would have aborted will continue to run. This is sometimes preferable.

Some languages, including C and C++, completely remove assertions at compile time using the preprocessor. Java requires an option to be passed to the run-time engine in order to enable assertions. Absent the option, assertions are bypassed, but they always remain in the code unless optimised away by a JIT compiler at run-time or excluded by an if(false) condition at compile time, thus they need not have a run-time space or time cost in Java either.

Programmers can always build checks into their code that are always active by bypassing or manipulating the language's normal assertion-checking mechanisms.

Read more about this topic:  Assertion (computing)

Famous quotes containing the words disabling and/or assertions:

    Criminality should be exterminated by disabling all notorious and irreclaimable criminals.
    Tennessee Claflin (1846–1923)

    Sometimes in conversation the sound of our own voice distracts us and misleads us into making assertions that in no way express our true opinions.
    Friedrich Nietzsche (1844–1900)