Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by nmilo

3 hours ago

If your assert compiles down to `if (condition) {}` in production then the compiler will optimize away the condition while keeping any side effects.

1 comment

nmilo

Reply

IshKebab  40 minutes ago

Yeah which may not be what you want. E.g. `assert(expensive_to_compute() == 0)`.

The correct way to solve this is with debug asserts (as in Rust, or how the parent described).

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities