Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #123 Assert condition

Verify that predicate isConsistent returns true, otherwise report assertion violation.
Explain if the assertion is executed even in production environment or not.

if !isConsistent() {
	panic("State consistency violated")
}

Go doesn't provide assertions.
But it's still possible to crash when desired.
#include <assert.h>
assert(isConsistent());

If NDEBUG is defined, the assert macro becomes void. Therefore, such expressions must not have side effects.

New implementation...
< >
programming-idioms.org