Hi,
I would recommend novice programmers to write A LOT of debug/log messages.
For example,
For every function, write at least two debug lines that print
1. Function name and it's start with value of parameters
2. Result of function. |
Could you consider using a debugger instead? If you are using an IDE, there should hopefully be a GUI debugger built in.
There are also
assert
These will end a program if some user condition is not met, forcing one to fix the problem, They aren't in the release version.
Debug statements can be a pain: Have to recompile, have to remove them later, make a mess of the code.
Although I can understand writing to a log file for runtime warnings. By runtime warnings, I mean the situation where an error in 1 data item doesn't mean the whole thing needs to be abandoned, but it is useful to print to a log file which items had a problem.
Additionally, print error/warning messages if parameter values and result are out of expected range. |
This is called contract programming. It has preconditions and post conditions. I think you need more than printing of messages for this, because that situation violates an invariant(s). So you might need to consider doing something more hard nosed, like throwing an
exception
. Or if exceptions are not desirable, return a
std::tuple
with error info, or a status
enum
. A status
enum
can be dealt with with a
switch
.
Another concept is to make your code difficult to use badly, and easy to use properly. For example
Scott Meyers has a Date class which uses a
class
for each and every month. This way, he avoids problems with the order in short dates with American vs other formats.
Anyway, I think it's great that you are thinking about these things already - Good Luck!!