Framework vs. Toolkit vs. Library
Don't call Us, We'll call You.
Even tho this question is highly subjective, my personal opinion about those two is this:
Framework: this describes a given structure of “how” you should present your code. Pretty much like a code-template, along some helpers, constructors etc. to solve/simplify a specific problem or bring your architecture in “order”. Examples, “Backbone“, “requireJS“, “socketIO“.
Library: Is an entire toolkit which highly abstracts different layers, like browsers / DOM models / etc. Also as a good toolkit, it offers a lot of tools and neat stuff to work with, which in general, simplify your coding experience. Examples “jQuery“, “MooTools“, “YUI“
I agree with jAndy, in my opinion a framework imposes structure upon your code in order to address a particular problem and a library is a generic set of tools that aid you in various tasks, without necessarily addressing the same problem.
In this respect:
jQueryis a library because it abstracts a lot of browser incompatibilities but imposes no structure on your code.
underscore.jsis a library because it’s a collection of utilities to manipulate data structures and other goodies.
backbone.jsis a framework because it structures your front-end code to match the MVC pattern.
Jasmineis a framework because it structures your code so that you can do BDD easily.
Regarding your suggested example, frameworks fit the
don't call us paradigm, because most of them impose the flow of the code (some sort of inversion of control). You call the libraries, they don’t call your code.
This is a subjective opinion, so take it as such.
A framework encapsulates common application functionality, allowing the developer to focus on the parts that are unique to their application. That means the developer writes pieces of code that get called by the framework when various things happen; Ex:
Libraries are packages of code that typically get called by your application to perform a task, like DOM manipulation or HTTP requests. Ex:
There is no real definition of the difference between those two, but in general I would say that a framework is a more general “multi-tool” thing than a library, which is usually very specialized.
For example, Sylvester is a matrix and vector math library. It is very specific in its functionality.
A framework like Prototype on the other hand offers much more than just a limited set of very specialized functionality. It may even use or consist of multiple libraries internally.
In the end, people use “framework” and “library” as they see fit. Unfortunately 😉