B
bill
I firmly believe that it is always a bad idea to put code in a header
file. Nothing pisses me off more than seeing function definitions in a
..h, and I recently was truly blessed to witness code that actually
contained #include "foo.c" in a header. However, I am eliciting
responses to the thought of putting assertions in a header file. I am
dealing with a really ugly, really poorly done code base, and I find
myself often thinking "wtf? Does this mean what I think it does?" In
such cases, I usually like to trow in an assertion to confirm things.
My aesthetic sense tells to clean out all of the header files, my
realistic sense tells me to dump the whole thing and start over, but my
practical sense tells me that either of those solutions will take
months. So I'm putting assertions into header files, and it makes me
feel dirty. Am I compounding an already horrible situation? When
possible, I use:
#if FOO != BAZ
#error
#endif
but in a case where the header already has run-time code, I need to use
an assertion. Believe me, I would love to simply pull the code out of
the headers, but the build environment is so phenomenally convoluted
that changing the file structure is a major headache. I suppose that
in this situation, aesthetics and good style are totally pointless
concerns, but I still have some dignity.
So, what do you think. Is it acceptable to put an assertion into a
header file?
file. Nothing pisses me off more than seeing function definitions in a
..h, and I recently was truly blessed to witness code that actually
contained #include "foo.c" in a header. However, I am eliciting
responses to the thought of putting assertions in a header file. I am
dealing with a really ugly, really poorly done code base, and I find
myself often thinking "wtf? Does this mean what I think it does?" In
such cases, I usually like to trow in an assertion to confirm things.
My aesthetic sense tells to clean out all of the header files, my
realistic sense tells me to dump the whole thing and start over, but my
practical sense tells me that either of those solutions will take
months. So I'm putting assertions into header files, and it makes me
feel dirty. Am I compounding an already horrible situation? When
possible, I use:
#if FOO != BAZ
#error
#endif
but in a case where the header already has run-time code, I need to use
an assertion. Believe me, I would love to simply pull the code out of
the headers, but the build environment is so phenomenally convoluted
that changing the file structure is a major headache. I suppose that
in this situation, aesthetics and good style are totally pointless
concerns, but I still have some dignity.
So, what do you think. Is it acceptable to put an assertion into a
header file?