DEV Community

Nick Shattuck
Nick Shattuck

Posted on

What is the difference between a Library vs A Framework?

I see these terms tossed around a lot. I've Googled them myself but the explanations I find are very cryptic. Would anyone mind explaining (simply if possible) what the differences are?

Latest comments (22)

Collapse
 
scottshipp profile image
scottshipp

If the maintainers call it a library, it's a library.

If the maintainers call it a framework, it's a framework.

🤣

Collapse
 
nhidtran profile image
nhidtran

I view library in the traditional sense. It has books/functions/modules that you can/might not use.
And a framework like a “frame of mind”. Your house was built within a framework and there are certain things you need to do within that framework and those guidelines to build it right

Collapse
 
thomasjunkos profile image
Thomas Junkツ • Edited

I would say they have in common to deal with one specific topic.
Depending on the level of abstraction you either call it framework or library.

Say you have code dealing with web requests, you are looking at a request library.
Say you have code dealing with authorization, you are looking at an auth library.
Say you have code dealing with database related things, you are looking at a db library.

If you have code dealing with building web applications, you are looking at a web framework.
From what was said, it is easy to see that a web framework itself could consist of several libraries, e.g. request, auth and db.

OTOH, I assume those terms emerged somewhere in time and there was no clear definition in the first place.

Collapse
 
ricaudbenoit profile image
br

A library is any package you can add to any project structure of your own. A framework is the very project structure you can build your project onto.

Collapse
 
tzesien profile image
Tze-Sien

Let's take baking cake as an example.

Library
You bake your cake on your own, but you probably not going to grow the strawberry which is your ingredients, so you buy it from stores(library)
You control the whole process of baking(programming) to bake a cake(program)

Framework
In this case, you get a cake by buying it from bakery.
In this case, you can decide only few things like the color, flavour or design. The whole process will be controlled by Baker(framework)

Hope this can help you understand it better. ^^

Collapse
 
belinde profile image
Franco Traversaro

All the responses are good in their own ways, so I'll go for brevity.

A library is a component doing a specific task, and you can use it wherever you want.

A framework is a bunch of libraries PLUS an opinionated way to use them, to reduce the boilerplate you have to write.

Typically if you are writing a project from scratch and you install just a library, your software does nothing. But if you install a framework you'll have already something working, like a website with a homepage and a login system.

Collapse
 
swarupkm profile image
Swarup Kumar Mahapatra

Your code controls a "library".
Your code is controlled by a "framework".

Collapse
 
cchacin profile image
Carlos Chacin ☕👽

I would say that a library is an utility that you code calls, and a framework is a set of libraries that call your code in order to provide you a set of functionalities.

Collapse
 
xanderyzwich profile image
Corey McCarty

In addition the already great answers the best way that I've heard it put is that a framework is an extention of the language where a library is like a chunk of code that you bring in instead of writing.

Collapse
 
ghost profile image
Ghost

To me a library is a hammer, a framework is a workshop and API where you ask somebody else to put the nail for you.