Importance of Debug/Log messages

I would consider myself a novice programmer who is about to become intermediate one. XD

I have been working on my personal project about a few months and I am realizing how well-written/frequent Debug/Log messages can help development and maintaining software... A LOT.

I am writing a blog post about this and I would like to have your opinions.


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.

Additionally, print error/warning messages if parameter values and result are out of expected range.


What do you think? Do you think spending a good amount of time writing debug/log messages is wasteful? or actually very helpful?
Last edited on
In point of view,
Debug log messages are very useful for debugging purpose. Printing error log warn is much useful, but should avoid the displaying the results in looping .
There is no need to print the info. every time but sometimes it requires to print the path value will store with aid of error /warns.

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!!

Topic archived. No new replies allowed.