DEV Community

Discussion on: What's the difference between a library and a framework?

Collapse
 
sylwiavargas profile image
Sylwia Vargas

Frameworks are opinionated. Libraries are pieced together to make your own framework.

This is exactly the thing I came to say here.

React is a library and as such, it "gives you tools to build your own toolbox".

Rails is a framework and as such, it gives you opinions on how you should do things with its own tools/solutions.

Collapse
 
peerreynders profile image
peerreynders

From the same article:

Offramp: For me, this is one of the benefits of libraries vs frameworks. Especially at a larger scale, you start by using a framework, but at some later point in time, you find yourself having outgrown the framework (or the framework has stagnated for too long), and you want to switch. This can be really hard, because frameworks shape your code, and each framework is different, so there is no easy migration path. The contact surface with libraries, on the other hand, is often very small, making a switch from one library to another a much smaller task, with a low blast radius.

Because "frameworks shape your code" they are imposing their own constraints that shape (, constrain, and impact) your solution architecture—that in my mind is expressing an "opinion", a vision of how things should be done.

So frameworks are inherently opinionated.

Concretely one can move from React, to Preact because Preact deliberately mirrors React (to a point). It's going to be more work to move to something like Inferno or even SolidJS. By the time we get to Svelte we're mostly talking about a rewrite.

To me the whole "React is unopinionated" narrative is mostly marketing because it's less opinionated than other frameworks which by design are more prescriptive—because their community values:

"There should be one-- and preferably only one --obvious way to do it."

PEP 20 – The Zen of Python