Share on Facebook Share on Twitter Email
Answers.com

assert

 
(ə-sûrt') pronunciation
tr.v., -sert·ed, -sert·ing, -serts.
  1. To state or express positively; affirm: asserted his innocence.
  2. To defend or maintain (one's rights, for example).
idiom:

assert oneself

  1. To act boldly or forcefully, especially in defending one's rights or stating an opinion.

[Latin asserere, assert- : ad-, ad- + serere, to join.]

assertable as·sert'a·ble or as·sert'i·ble adj.
asserter as·sert'er or as·ser'tor n.

Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
Roget's Thesaurus:

assert

Top

verb

  1. To put into words positively and with conviction: affirm, allege, argue, asseverate, aver, avouch, avow, claim, contend, declare, hold, maintain, say, state. Idioms: have it. See affirm/deny/argue.
  2. To defend, maintain, or insist on the recognition of (one's rights, for example): claim, vindicate. See attack/defend.


v

Definition: insist, declare, maintain
Antonyms: deny, reject

Word Tutor:

assert

Top
pronunciation

IN BRIEF: To state with certainty; declare.

pronunciation Assert your right to make a few mistakes. If people can't accept your imperfections, that's their fault. — Dr. David M. Burns

LearnThatWord.com is a free vocabulary and spelling program where you only pay for results!

Random House Word Menu:

categories related to 'assert'

Top
Random House Word Menu by Stephen Glazier
For a list of words related to assert, see:

  See crossword solutions for the clue Assert.
Wikipedia on Answers.com:

Assertion (computing)

Top

In computer programming, an assertion is a predicate (for example a true–false statement) placed in a program to indicate that the developer thinks that the predicate is always true at that place.

For example, the following code contains two assertions:

x := 5;
{x > 0}
x := x + 1
{x > 1}

x > 0 and x > 1, and they are indeed true at the indicated points during execution.

Programmers can use assertions to help specify programs and to reason about program correctness. For example, a precondition — an assertion placed at the beginning of a section of code — determines the set of states under which the programmer expects the code to execute. A postcondition — placed at the end — describes the expected state at the end of execution.

The example above uses the notation for including assertions used by C.A.R. Hoare in his 1969 paper.[1] That notation cannot be used in existing mainstream programming languages. However, programmers can include unchecked assertions using the comment feature of their programming language. For example, in C:

x = 5;
x = x + 1;
// {x > 1}

The braces included in the comment help distinguish this use of a comment from other uses.

Several modern programming languages include checked assertions - statements that are checked at runtime or sometimes statically. If an assertion evaluates to false at run-time, an assertion failure results, which typically causes execution to abort. This draws attention to the location at which the logical inconsistency is detected and can be preferable to the behaviour that would otherwise result.

The use of assertions helps the programmer design, develop, and reason about a program.

Contents

Usage

In languages such as Eiffel, assertions form part of the design process, and in others, such as C and Java, they are used only to check assumptions at runtime. In both cases, they can be checked for validity at runtime but can usually also be suppressed.

Assertions in design by contract

Assertions can function as a form of documentation: they can describe the state the code expects to find before it runs (its preconditions), and the state the code expects to result in when it is finished running (postconditions); they can also specify invariants of a class. Eiffel integrates such assertions into the language and automatically extracts them to document the class. This forms an important part of the method of design by contract.

This approach is also useful in languages that do not explicitly support it: the advantage of using assertion statements rather than assertions in comments is that the program can check the assertions every time it runs; if the assertion no longer holds, an error can be reported. This prevents the code from getting out of sync with the assertions (a problem that can occur with comments).

Assertions for run-time checking

An assertion may be used to verify that an assumption made by the programmer during the implementation of the program remains valid when the program is executed. For example, consider the following Java code:

 int total = countNumberOfUsers();
 if (total % 2 == 0) {
     // total is even
 } else {
     // total is odd and non-negative
     assert(total % 2 == 1);
 }

In Java, % is the remainder operator (or modulus) — if its first operand is negative, the result can also be negative. Here, the programmer has assumed that total is non-negative, so that the remainder of a division with 2 will always be 0 or 1. The assertion makes this assumption explicit — if countNumberOfUsers does return a negative value, the program may have a bug.

A major advantage of this technique is that when an error does occur it is detected immediately and directly, rather than later through its often obscure side-effects. Since an assertion failure usually reports the code location, one can often pin-point the error without further debugging.

Assertions are also sometimes placed at points the execution is not supposed to reach. For example, assertions could be placed at the default clause of the switch statement in languages such as C, C++, and Java. Any case which the programmer does not handle intentionally will raise an error and the program will abort rather than silently continuing in an erroneous state.

In Java, assertions have been a part of the language since version 1.4. Assertion failures result in raising an AssertionError when the program is run with the appropriate flags, without which the assert statements are ignored. In C, they are added on by the standard header assert.h defining assert (assertion) as a macro that signals an error in the case of failure, usually terminating the program. In standard C++ the header cassert is required instead. However, some C++ libraries still have the assert.h available.

The danger of assertions is that they may cause side effects either by changing memory data or by changing thread timing. Assertions should be implemented carefully so they cause no side effects on program code.

Assertion constructs in a language allow for easy test-driven development (TDD) without the use of a third-party library.

Assertions during the development cycle

During the development cycle, the programmer will typically run the program with assertions enabled. When an assertion failure occurs, the programmer is immediately notified of the problem. Many assertion implementations will also halt the program's execution — this is useful, since if the program continued to run after an assertion violation occurred, it might corrupt its state and make the cause of the problem more difficult to locate. Using the information provided by the assertion failure (such as the location of the failure and perhaps a stack trace, or even the full program state if the environment supports core dumps or if the program is running in a debugger), the programmer can usually fix the problem. Thus assertions provide a very powerful tool in debugging.

Static assertions

Assertions that are checked at compile time are called static assertions. They should always be well-commented.

Static assertions are particularly useful in compile time template metaprogramming, but can also be used in low-level languages in C by introducing illegal code if (and only if) the assertion fails. For example, in C a static assertion can be implemented like this:

#define COMPILE_TIME_ASSERT(pred) switch(0){case 0:case pred:;}
 
COMPILE_TIME_ASSERT( BOOLEAN CONDITION );

If the (BOOLEAN CONDITION) part evaluates to false then the above code will not compile because the compiler will not allow two case labels with the same constant. The boolean expression must be a compile-time constant value, for example (sizeof(int)==4) would be a valid expression in that context. This construct does not work at file scope (i.e. not inside a function), and so it must be wrapped inside a function.

Another popular [2] way of implementing assertions in C is:

static char const static_assertion[ (BOOLEAN CONDITION)
                                    ? 1 : -1
                                  ] = {'!'};

If the (BOOLEAN CONDITION) part evaluates to false then the above code will not compile because arrays may not have a negative length. If in fact the compiler allows a negative length then the initialization byte (the '!' part) should cause even such over-lenient compilers to complain. The boolean expression must be a compile-time constant value, for example (sizeof(int)==4) would be a valid expression in that context.

Both of these methods require a method of constructing unique names. Modern compilers support a __COUNTER__ preprocessor define that facilitates the construction of unique names, by returning monotonically increasing numbers for each compilation unit.[3]

C11 and C++11 provide static assertions through the use of static_assert.

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.

Comparison with error handling

It is worth distinguishing assertions from routine error-handling. Assertions should be used to document logically impossible situations and discover programming errors — if the impossible occurs, then something fundamental is clearly wrong. This is distinct from error handling: most error conditions are possible, although some may be extremely unlikely to occur in practice. Using assertions as a general-purpose error handling mechanism is unwise: assertions do not allow for recovery from errors; an assertion failure will normally halt the program's execution abruptly. Assertions also do not display a user-friendly error message.

Consider the following example of using an assertion to handle an error:

  int *ptr = malloc(sizeof(int) * 10);
  assert(ptr);
  // use ptr 
  ...

Here, the programmer is aware that malloc will return a NULL pointer if memory is not allocated. This is possible: the operating system does not guarantee that every call to malloc will succeed. If an out of memory error occurs the program will immediately abort. Without the assertion, the program would continue running until ptr was dereferenced, and possibly longer, depending on the specific hardware being used. So long as assertions are not disabled, an immediate exit is assured. But if a graceful failure is desired, the program has to handle the failure. For example, a server may have multiple clients, or may hold resources that will not be released cleanly, or it may have uncommitted changes to write to a datastore. In such cases it is better to fail a single transaction than to abort abruptly.

See also

References

External links


Translations:

Assert

Top

Dansk (Danish)
v. tr. - hævde, påstå

idioms:

  • assert oneself    gøre sig gældende, hævde sig

Nederlands (Dutch)
stellig beweren, erkenning eisen (van rechten etc.), bewijzen, onderbouwen

Français (French)
v. tr. - affirmer, soutenir, protester de, défendre, revendiquer, faire respecter

idioms:

  • assert oneself    faire valoir ses droits

Deutsch (German)
v. - behaupten, geltend machen, bestehen auf

idioms:

  • assert oneself    sich behaupten, sich durchsetzen

Ελληνική (Greek)
v. - βεβαιώνω, ισχυρίζομαι, υποστηρίζω, διεκδικώ, επιβάλλω, δηλώνω κατηγορηματικά

idioms:

  • assert oneself    επιβάλλομαι, υψώνω το ανάστημά μου

Italiano (Italian)
sostenere, insistere

idioms:

  • assert oneself    tenere duro

Português (Portuguese)
v. - insistir, defender, declarar, reclamar

idioms:

  • assert oneself    defender-se

Русский (Russian)
утверждать, заявлять, предъявлять претензию

idioms:

  • assert oneself    отстаивать свои права

Español (Spanish)
v. tr. - afirmar, mantener, sostener, hacer valer

idioms:

  • assert oneself    imponerse, infundir respeto

Svenska (Swedish)
v. - hävda, påstå, kräva

中文(简体)(Chinese (Simplified))
声称, 断言, 主张拥有, 坚持, 维护, 显示

idioms:

  • assert oneself    坚持自己的权利

中文(繁體)(Chinese (Traditional))
v. tr. - 聲稱, 斷言, 主張擁有, 堅持, 維護, 顯示

idioms:

  • assert oneself    堅持自己的權利

한국어 (Korean)
v. tr. - 단언하다, 시위하다

idioms:

  • assert oneself    자기의 권리를 주장하다, 주제넘게 나서다

日本語 (Japanese)
v. - 断言する, 主張する, 擁護する

idioms:

  • assert oneself    自説を主張する, でしゃばる, 現れる

العربيه (Arabic)
‏(فعل) يجزك, يؤكد, يدافع عن حق‏

עברית (Hebrew)
v. tr. - ‮טען, הצהיר, הביע, הגן על, עמד על דעתו‬


 
 

 

Copyrights:

American Heritage Dictionary. The American Heritage® Dictionary of the English Language, Fourth Edition Copyright © 2007, 2000 by Houghton Mifflin Company. Updated in 2009. Published by Houghton Mifflin Company. All rights reserved.  Read more
Roget's Thesaurus. Roget's II: The New Thesaurus, Third Edition by the Editors of the American Heritage® Dictionary Copyright © 1995 byHoughton Mifflin Company. Published by Houghton Mifflin Company. All rights reserved.  Read more
Answers Corporation Antonyms by Answers.com. © 1999-present by Answers Corporation. All rights reserved.  Read more
Word Tutor. Copyright © 2004-present by eSpindle Learning, a 501(c) nonprofit organization. All rights reserved.
eSpindle provides personalized spelling and vocabulary tutoring online; sign up free Read more
Random House Word Menu. © 2010 Write Brothers Inc. Word Menu is a registered trademark of the Estate of Stephen Glazier. Write Brothers Inc. All rights reserved.  Read more
 Rhymes. Oxford University Press. © 2006, 2007 All rights reserved.  Read more
Bradford's Crossword Solver's Dictionary. Collins Bradford's Crossword Solver's Dictionary © Anne Bradford, 1986, 1993, 1997, 2000, 2003, 2005, 2008 HarperCollins Publishers All rights reserved.  Read more
Wikipedia on Answers.com. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article Assertion (computing) Read more
Translations. Copyright © 2007, WizCom Technologies Ltd. All rights reserved.  Read more

Follow us
Facebook Twitter
YouTube

Mentioned in

» More» More