News for hackers. Stuff that matters.
Re:The Compiler Is Your Best Friend, Stop Lying to It by eterm on Wednesday December 31, 2025 @12:36PM (#46446282)
Better yet, `assert(false, message)`, with the message what you would have written in the comment.
Re:The Compiler Is Your Best Friend, Stop Lying to It by addaon on Wednesday December 31, 2025 @12:38PM (#46446320)
`assert(false)` is pronounced "this can never happen." It's reasonable to add a comment with /why/ this can never happen, but if that's all the comment would have said, a message adds no value.
Re:The Compiler Is Your Best Friend, Stop Lying to It by eterm on Wednesday December 31, 2025 @12:43PM (#46446379)
Oh I agree, literally `assert(false, "This cannot happen")` is useless, but ensuring message is always there encourages something more like, `assert(false, "This implies the Foo is Barred, but we have the Qux to make sure it never is")`.

Ensuring a message encourages people to state the assumptions that are violated, rather than just asserting that their assumptions (which?) don't hold.

Re:The Compiler Is Your Best Friend, Stop Lying to It by breatheoften on Wednesday December 31, 2025 @04:56PM (#46448779)
what language are we talking about? If it's cpp then the pronounciation depends on compiler flags (perhaps inferred from CMAKE_BUILD_TYPE)
Re:The Compiler Is Your Best Friend, Stop Lying to It by andrewf on Wednesday December 31, 2025 @11:42PM (#46451364)
Swap the parameters around for C++ and similar langs where `assert(a, b)` evaluates the same as `(void) a; assert(b)`.