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.
Emacs comment: Since Emacs is my IDE of choice, I have it slightly gray out the assert statements which helps reduce the feeling of clutter that they can provide. Here's what I add to my .emacs file:
; gray out the "assert(...)" wrapper (add-hook 'c-mode-common-hook (lambda () (font-lock-add-keywords nil '(("\\<\\(assert\(.*\);\\)" 1 '(:foreground "#444444") t))))) ; gray out the stuff inside parenthesis with a slightly lighter color (add-hook 'c-mode-common-hook (lambda () (font-lock-add-keywords nil '(("\\<assert\\(\(.*\);\\)" 1 '(:foreground "#666666") t)))))