Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping a library dependency-free

I have a small Utility library containing some useful utility methods which have been fully unit-tested. At the moment, my library has no external dependencies. I am toying with the idea of adding logging to my classes which might be useful for debugging purposes. But this would mean bundling logging libraries along with my project.

My question is: should I keep my library dependency free? Are there any advantages of doing so?

like image 932
dogbane Avatar asked Oct 26 '10 07:10

dogbane


People also ask

What are dependencies of a library?

Dependency on libraries. If a module or mediation module needs to use resources from a library or if a library needs to use resources from another library, you have to open the module or library with the dependency editor and add a dependency on the required library.

What is difference between dependency and library?

Typically, a library is also something that is not executable, but requires the consumption. A dependency, like the earlier answer suggested, is a relationship between two pieces of code. The first code calls out to the second code to either perform an action or return some information.

What is dependency management system?

Dependency management is a technique for identifying, resolving, and patching dependencies in your application's codebase. A dependency manager is a software module that helps integrate external libraries or packages into your larger application stack.


3 Answers

I would add a logging interface that the can be used to abstract the logging. Then the allow users to add logging via this interface. You too should use this interface, and you should supply a 'NullLogger' built into your library that would be used if no other logging is needed.

You can make it easy to not use the NullLogger by asking users to configure a new one, simply by config file or by run time discovery.

like image 76
Preet Sangha Avatar answered Oct 17 '22 11:10

Preet Sangha


Use Java Logging. It's part of JRE/JDK so no external libs are needed.

Check out examples.

like image 1
Peter Knego Avatar answered Oct 17 '22 12:10

Peter Knego


There are many advantages of doing so, not the least the ability to run on most any operating system.

One way of keeping your library pretty dependency free, is to require it to initialized prior to use. Then you would in your_lib_init(); function take a function pointer to logging backend. This means, the backend can be rewritten for any platform it might run on.

Also figure out, if you want a library totally free of all library dependencies, or one that depends on the standard class path. If it is pure Java, it will run on J2ME, Android, native compiled Java with GCJ and what not. If it uses class path, it will be portable across all class path implementations, in practice wherever OpenJDK runs.

like image 1
Prof. Falken Avatar answered Oct 17 '22 12:10

Prof. Falken