DEV Community

jebuscraisp
jebuscraisp

Posted on

What is the difference between a library and a framework?

Top comments (2)

Collapse
 
alainvanhout profile image
Alain Van Hout

Rather than focus on definitions of what constitutes a 'library' and what constitutes a 'framework', I would like to draw attention to a typical difference between them:

  • in case of a library, you can at any specific instance choose to make use of the library or do things manually (or perhaps use yet another library)
  • in case of a framework, doing something outside of the framework generally requires some additional work to 'get things working', even before you can start implementing your own approach for that specific instance

An example of the first is when you want to calculate something using a math library, or want to use a manual implementation that is a slight variation of the same formula/algorithm.

An example of the second: You typically do http calls with the services of a framework, which helps you by immediately interpreting the response as a json string and converting it to an actual object or data structure. Now you want to do an http call but want to process the raw http response body because it's something quite different from json. The usual way for that doesn't allow that, so you have to resort to a workaround, which is a bit of a hassle since it works against the assumptions of the framework.

Do note that this isn't meant as a case against frameworks: the assumptions that frameworks rely on can something become an issue, but for a large part of the time those assumptions reduce the amount of effort that you need to do. Whether the issues outweigh the advantages, that's a matter of circumstance.

Collapse
 
rhymes profile image
rhymes