The Difference Between Library and Framework

natasha selvidge
2 min readSep 10, 2021

Let’s start with the biggest similarity between these two concepts. Both frameworks and libraries are reusable codes written by one or more developers that are used to help solve common problems. The biggest difference may seem strange, but it follows the “Hollywood principle”.

Hollywood Principle:

Library says: Just call me when you need me.

Framework says: Don’t call me, I’ll call you.

When you use a library, you are in charge of the flow of the application. You are choosing when and where to call the library.

When you use a framework, the framework is in charge of the flow. It provides some places for you to plug in your code, but it calls the code you plugged in as needed. Professionally speaking: The difference between a library and a framework lies in a term called “Inversion of Control”. When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you.

Library is just a collection of routines (functional programming) or class definitions (object oriented programming). The classes or routines normally define specific operations in a domain specific area. For instance, you could create a library that draws charts for you input, a library that parses JSON data or a library that performs some reusable mathematical operations and that way you can avoid writing that boilerplate code every single time.

In framework, all the control flow is already there, and there are a bunch of predefined white spots that we should fill out the skeleton.

I would say one of my personal favorites is React. Usually considered a library, React is sometimes referred to as a framework. In the context of the MVC approach to creating a large-scale application, React provides the view portion. I recently started learning Ember.js too. There is something profound about a framework that refers to itself as a “Framework for ambitious web developers.” Some well-known companies like Microsoft, Netflix, and LinkedIn use Ember.js because it employs the (MVVM) Model-View-View-Model pattern and incorporates best practices as part of the framework. Best of all, it scales really well.

Interestingly, while Ember.js focuses on web development, you can also use it to build mobile and desktop applications — it was used to build Apple Music. Okay, enough about Ember.js. Maybe I will make a post on this new framework I have been dabbling in.

Which frameworks and libraries do you use the most and why?

--

--