I have built a library that is being used by a few people. They say that library has a few print statements which is wrong because a library should give freedom to users to use the library the way they want and forcing a few print statements is not good that way. Should there be print statements in a library by any ideology ?
-
2Are the print statements for logging?– Erik EidtCommented Apr 30, 2016 at 14:45
-
3Possible duplicate of Should You Log From Library Code?– gnatCommented Apr 30, 2016 at 14:46
-
Not exactly. Just to print some info. like printing return value before returning it, so that when library is being tested as standalone, its output is visible.– Gaurav KumarCommented Apr 30, 2016 at 14:47
-
4Printing is a pretty big and unexpected side effect for a function. It's also going to slow things down. There are better ways to test things. It is ok (good even, see @gnat's reference) to log if you allow the choice of logging to be the library user's not the library's, and it includes choices to expand/limit verbosity.– Erik EidtCommented Apr 30, 2016 at 15:05
-
@ErikEidt Plus, of course, when you use a library, there might not be a destination to print to.– Ross PattersonCommented Apr 30, 2016 at 23:33
Add a comment
|
1 Answer
Absolutely not, no. I don't want your library spewing noise onto the console, into a log file or whatever else.
At least, that should be the default behaviour. If you really need it, have a way to set a "debug" flag which turns this kind of logging on. However, you shouldn't need that for normal testing - that's done by checking the return values in some kind of test harness, not by logging things.
-
4Provide a debug flag, or a way to provide a custom file descriptor to which to write things, or even a print/log callback -- but give the policy control for such printing to the consuming application, please. Commented Apr 30, 2016 at 16:36