Assertions in Programming

The cluster debates the proper use of assert macros, especially in C, questioning whether they should be enabled in production builds for invariant checks or limited to debug mode, versus using regular runtime checks for errors.

➡️ Stable 0.6x Programming Languages
1,896
Comments
20
Years Active
5
Top Authors
#596
Topic ID

Activity Over Time

2007
4
2008
4
2009
24
2010
17
2011
51
2012
52
2013
96
2014
81
2015
57
2016
144
2017
105
2018
121
2019
136
2020
120
2021
111
2022
181
2023
213
2024
158
2025
199
2026
22

Keywords

GP IMO TCP LoopAccessAnalysis.cpp ERROR BUGS NDEBUG BUG i.e API assert asserts assertions assertion checks debug error code tests exceptions

Sample Comments

randyrand • Aug 8, 2021 • View on HN

C has always had Asserts for that reason.

nimmer • Jun 10, 2020 • View on HN

Plus, assert() is commonly used for runtime checks, not static analysis.

etix • Apr 18, 2014 • View on HN

The most questionable thing is why did they keep the assert in production code. Looks like unfinished job to me.

TeMPOraL • May 6, 2016 • View on HN

Well, the lesson here is to not use asserts for that task. Asserts are by definition checks that are meant not to be included in release versions. If checking some invariant matters to you in the actual application (as opposed to just being a debugging convenience), then do a normal check.

IshKebab • Jul 17, 2025 • View on HN

Doesn't matter. Assertions should be used for things that are always true (barring bugs in the program). That isn't the case here.

int_19h • Nov 9, 2022 • View on HN

What's bizarre about asserts being disabled if you explicitly ask for it?

paulgb • Sep 27, 2007 • View on HN

Assertions are in the code. And they can really be helpful.

im3w1l • Oct 9, 2023 • View on HN

It's undefined behavior if the assert triggers in production. It's too greedy for minor performance benefit at the risk of causing strange issues.

Kristine1975 • Mar 31, 2016 • View on HN

Isn't that what assertions are for?

tptacek • Nov 19, 2025 • View on HN

Probably because this case was something more akin to an assert than an error check.