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 ?

  • 2
    Are the print statements for logging?
    – Erik Eidt
    Commented Apr 30, 2016 at 14:45
  • 3
    Possible duplicate of Should You Log From Library Code?
    – gnat
    Commented 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. Commented Apr 30, 2016 at 14:47
  • 4
    Printing 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 Eidt
    Commented Apr 30, 2016 at 15:05
  • @ErikEidt Plus, of course, when you use a library, there might not be a destination to print to. Commented Apr 30, 2016 at 23:33

1 Answer 1


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.

  • 4
    Provide 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.
    – Castaglia
    Commented Apr 30, 2016 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.