Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • assert(window != nullptr);? So crashing the entire application is always the answer? Without context for the code's use, it's flat-out wrong to assume crashing the entire process is acceptable. Nevermind if that code is ever compiled with NDEBUG defined the check disappears. Commented Oct 23 at 19:37
  • You didn't grasp the meaning of "cannot happen". By hypothesis, all the caller sites are in the same codebase where we defined the library routine, and are available to static analysis. An if (window) ... lets a buggy call site off the hook, gives it a pass, doesn't break the build. OTOH assert tells static analysis loud and clear that a buggy caller which might pass in nullptr should definitely break the build, so we don't ship clearly broken code. I want no ambiguity about whether caller might be good or might be bad. If it could pass a nullptr, then we die in CI/CD, not in production. Commented Oct 23 at 22:00
  • LOL. You've never seen a bug from something that "cannot happen", I guess. I don't care what any API guarantees seem to say, if you're getting a pointer value from an uncontrolled caller there's no such thing as "cannot happen". And what's restricted today to a limited number of controlled callers that "ensure" things that "cannot happen" can all too easily change in the future. Avoiding reality by saying it "cannot happen"? Reality is not limited by what you can think of. Commented Oct 23 at 23:32
  • (cont) And if your CI/CD isn't complete enough to catch a bug, it's not complete enough to catch a bug no matter how the bug manifests itself. Tossing an error exception or returning an error code on a nullptr can be tested for just as easily as an assertion failure. Commented Oct 23 at 23:38