We don't need no stinkin' assertions

Started by
11 comments, last by Nypyren 7 years, 2 months ago
Ew.


The actual change I made was to remove the assertion, add the new if/early-out, and write a 3 paragraph comment on why it was changed and when :-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement

As an alternative solution:


if (importantPointer == nullptr) return;

// keep all existing code
assert(importantPointer != nullptr);
....


That just leads to stuff like this (which I've actually seen in production code:


if (thing) 
{
   assert(thing);
}
else
{
   assert(!thing);
}

As an alternative solution:


if (importantPointer == nullptr) return;

// keep all existing code
assert(importantPointer != nullptr);
....


That just leads to stuff like this (which I've actually seen in production code:


if (thing) 
{
   assert(thing);
}
else
{
   assert(!thing);
}


Last time I saw that, it was because there was a data race and whoever added the asserts had no idea what was happening.

This topic is closed to new replies.

Advertisement