Is possible to write too many asserts?
Posted
by
Lex Fridman
on Programmers
See other posts from Programmers
or by Lex Fridman
Published on 2011-06-27T04:28:46Z
Indexed on
2011/06/27
8:30 UTC
Read the original article
Hit count: 260
I am a big fan of writing assert
checks in C++ code as a way to catch cases during development that cannot possibly happen but do happen because of logic bugs in my program. This is a good practice in general.
However, I've noticed that some functions I write (which are part of a complex class) have 5+ asserts which feels like it could potentially be a bad programming practice, in terms of readability and maintainability. I think it's still great, as each one requires me to think about pre- and post-conditions of functions and they really do help catch bugs. However, I just wanted to put this out there to ask if there is a better paradigms for catching logic errors in cases when a large number of checks is necessary.
© Programmers or respective owner