DEV Community

Michael Tharrington Subscriber for CodeNewbie

Posted on

What's the difference between a library and a framework?

Just like the title says, I'd like help understanding the difference between a library and a framework.

I'm a non-techie, so simple explanations and analogies are most definitely welcome. #explainlikeimfive 🙌

Bonus points if you can provide examples of each!

Top comments (21)

Collapse
 
giulio profile image
Giulio "Joshi" •

Oh, I love this question.

I'd attempt to work on it with a metaphor

A library is like a tool: offers you a specific set of functions, more or less like an amplifier, a drum trigger or a mixer.
Libraries tend to offer you API, that would be the tools user interface: functions on API are more or less like jacks and sockets, you can tune a library function with parameters like you can adjust settings with knobs and switches.

Since you need an example, I'd play the Log4J card here, a Java logging library quite known to be a security issue, theater of recent drama around the security world.

A framework feels more like a preset recording studio: it has its tool preferences (a set of libraries already ingrained), usually is already tuned for a set of known music genres (frameworks tend to offer their most-used case scenario as tutorials to reduce learning time) and stuff like that.

I mentioned already tuned because framework tend to be pretty bundled up with specific use case, and this time I mention Laravel.

Yes, it is PHP. It has improved a lot and deserves more love.

Like that old recording studio that never let you down, then a bad series of events drove you away from it ...and now it is growing back from its own ashes, happy to welcome you again.

Collapse
 
gmarie profile image
Gnintedem Marie •

Thanks a lot for the explanation, it's easy to picture the example and understand the principle.

Collapse
 
michaeltharrington profile image
Michael Tharrington •

Oooo this is awesome! Love the analogies to music production. Thanks so much for offering this thorough (and thoroughly enjoable) explanation, Giulio!

Collapse
 
peterwitham profile image
Peter Witham •

Such a great way to explain. I like it.

Collapse
 
montyharper profile image
Monty Harper •

Loving the more succinct descriptions. How about this:

A library provides.
A framework guides.

Collapse
 
rachelfazio profile image
Rachel Fazio •

This was awesome.

Collapse