What is the difference between a Library and a Framework

What is the difference between a Library and a Framework

Difference between Library and Framework, Coding Bishal, library, framework

The term framework and library are two terms that are used a lot in the tech industry, many people use them interchangeably and don't really understand what they mean so if you're on that boat hopefully this article will help you out.

In this article we are touching up the great subject of what is the difference between a library and framework yes you might have already touched that subject by looking up the definition of what library as well as in the framework but those definitions are not at all able to give you the whole perspective and is not able to make you understand what actually the individual subject means and also this is a common topic being asked in variety of programming interviews as well.

So let's go ahead and get started so today we're going to cover what is a library, what exactly is a framework and then we're going to compare both of them and see what the actual difference is.

What exactly is a library?

Well in gist a library is a set of code that was previously written that can be called upon when building your own code. So it's essentially a collection of code packed together that can be used over and over again and it's a very good idea to put frequently used functions together and build a library for your own self.

One of those reasons is handling-“Reusability”

So reusability is one of the most important factors in software development. Whenever some method is used you can simply make a method invocation using the library just imported.

For Example: You create a JavaScript function that will help in enabling dark mode in a website. You can keep this JavaScript function in a JS file and use that file in different projects or other web pages.

What is framework in programming?

Now let's take a look at what is a framework, in a gist a framework is a supporting structure where your own code defines the “meat” of the operations by filling out the structure. It essentially provides a scaffold on which to build software and allows a programmer to avoid writing any boilerplate code and merely fill in the blanks leaving the framework to decide when it's appropriate to execute any business logic.

In the framework, actually your framework calls your code and further your code can call to a library maybe. But notice the difference here when you use a library you are making a call to library function manually but in the framework, the framework is actually calling to your code.

Library vs. Framework explanation

So let's take a look at an analogy in order to drive this home let's pretend you're a construction worker and you're assigned to build a house. Now in theory you could build a house without using any tools but if you want to make your life easier you'd go ahead and use a hammer use a nail gun use a handsaw whatever you need.

So in senses all these tools are your library you're going to be using these tools to build a house and not only can you build a house with them you can y'all go ahead and build a table a chair or anything you like with these tools.

Now if we look at a framework well the supporting structure is going to be the framework itself so the framework dictates how your project will be structured where as libraries are more of the building blocks that can be used anywhere so the skeleton or foundation of the house is essentially your framework you're going to be adding to it and we're going to fill out the structure until it's completed and it comes together.

One key point to note here is that a framework may use libraries but it doesn't really need libraries in order to operate, so now we have an idea of what a framework in a library is but one of the biggest factors that differentiate a library and a framework is something called “inversion control”.

Inversion control

When we use frameworks and libraries our code flows a little bit different. Let's say you have your own code written and you import a library when you import a library you have access to all these methods that are collected pieces of functionality from that library so you're making calls directly to the library itself so when we use a library we are in charge of the flow of the application we are the ones choosing when and where to call the library.

On the other hand when we use a framework, the framework itself is making calls towards our code so the framework writer writes the application and leaves out the interesting details which we fill in so when using a framework the framework is in charge of the flow it provides some places you to plug in your code but it calls a code you plugged in as needed.

Now a lot of frameworks can get quite hefty and large like rails for example so for that reason many frameworks actually end up even using libraries but it's important to note that it's not a necessity for a framework to contain libraries.

Some actual popular frameworks and libraries

Okay so let's go ahead and take a look at some actual popular frameworks and libraries that are used around.

Some of the frameworks:

  • One of the main most popular frameworks which I just mentioned is “rails” which is a very popular beginner friendly framework that uses Ruby and makes it very easy to get started and set up a basic skeleton if you worked a lot with front-end development then you're probably familiar with angular which is a front-end framework that specializes in building rich single page applications.

  • There’s also DJango which is a framework that uses python for web development and it's used on by some of the big names such as Google, YouTube and instagram.

  • And we also have Express which is a back-end development framework that prides itself in being very minimal and fast.

So let's go ahead and take a look at some of the libraries

  • Now what are the most popular libraries which you've probably heard of is react and react is a JavaScript library by Facebook that's used for building user interfaces and single page applications.

  • There’s also jQuery which is a very old cycle library designed to help in manipulating HTML elements as well as the event handling and CSS animation.

  • Another library called Lodash is essentially a Productivity kit that provides a bunch of utility functions that you can use in your program right off the bat.

  • And last we have Redux which is another open source JavaScript library for managing applications state and it's commonly used with react.


So hopefully this article gave you a good understanding of what is a framework and a library and how they're actually different. Anyway thank you all for reading this article. If you find this article useful do share it with your friends.

Comments