logoalt Hacker News

UqWBcuFx6NV4rtoday at 12:36 AM1 replyview on HN

Ditto. I’ve certainly never used it and can’t recall seeing it in any codebases I’ve worked on or looked at. Sounds interesting though!

I’ve of course certainly heard of, seen, and used `assert`, but more often than not, outside of pytest, I see its use way more in potential footgun scenarios—I doubt that many people know that assertions can be silenced, and that they’d probably be better off raising exceptions in many cases where they’re using `assert`.


Replies

nneonneotoday at 1:14 AM

I made a CTF problem where `assert` was used as a critical safety check - and where "accidentally" running the program under -O (for speed!) resulted in a security vulnerability. A large fraction of the people who attempted the problem seemingly missed this bug.

I would not be surprised in the least if that pattern existed in the wild. In fact, it's quite common to see this in C/C++ codebases too: people will use assert() to check a security-relevant property, and then disable those checks in their release builds "because it can't happen".