Software framework vs library
A huge number of users are unaware of the significant difference between the Framework and library. If the user wants to be a good developer (or coder), this is very important to understand. The Framework is generally considered as the set of several libraries. However, this is not completely true. “Who calls for” means the caller/callee relationship defines the difference between both terms. If we talk about the libraries “it is the code written by the user that calls the code written by someone else in the library”.
So what is the actual meaning of the term “Library?”
In general, a library is a set or collection of predefined functions and classes that are available for developers to make their work a little easier and to boost the development process. This means that the code for these functions and classes is already written in the library and developers do not write code for some specific functionality, they can call and use code from the library through their own code.
In general terms, the size of any typical library is not that large. Although, normally libraries are focused on narrow scope such as strings, sockets, IO due to which the size of their API’s is also small and requires only a few numbers of dependencies. A library is just a set of classes with their definition.
Why we need a Library?
The answer to this question is very simple e.g. to reuse the code that has been already written by someone else (or other developers) which helps the developer to avoid writing code for some functionality for which code is already written in the library.
We can understand the vital role of the library with the help of an example:
Example
In some certain libraries, there is a method named “findLastInde()”. The definition of this method is written in order to find the index of a specific character in the string which is passed as the argument. So we can simply call the “findLastIndex(character to find)” method and pass the character as an argument by writing it in between the brackets e.g. “findLastIndex(A)” whose position we want to search.
How to create a Library?
Suppose we have a program in which we are planning to work with strings and we want to keep our code “DRY” (don’t repeat yourself) and will write a few reusable functions as shown in the following given program.
Program
So here we just created a library. However, we still required to save it to use these functions by just calling them.
CREATING AND USING OUR OWN LIBRARY CODE
To create a Library, follow the instructions given below:
- first of all, we have to create an INTERFACE to the library: mylib.h
- Now we have to create an IMPLEMENTATION of our library: mylib.c
- We have to Create a Library OBJ file (or Object File) e.g. (.o) that we can link with the programs that use the library.
- Now we can use the library in other c program’s code by including it in the program e.g. “#include<mylib.h>” and link in the code of the library into a.out file.
Frameworks
A frame work just gives us a basic structure around which we can add our code to have a significant functionality of that system. So it allows us a standard way of creating applications and it is the most important thing to keep in mind that if we use a framework to create an application obviously the framework forces us to work in a specific standard manner. Also we can learn a standard way of creating the websites and applications so that our applications and websites will be more standardized.
The functions defined in the framework are reusable which means if we want to use the same functionality in the several different places inside the project we can use that and we also don’t need to create that function because framework has done lots of work for us.
Another Definition of Framework
In short, we can say that a software framework is an abstraction in which the framework provides us with a common functionality that we can change or modify by writing additional code. This is how application-specific software is provided.
Example
Suppose we are working on a certain framework such as “Laravel” that has many functionalities and we talk about a single function which is just a use of eloquent model that provides us some functions that we can use anywhere in our project. In that case, we also do not require to write that functionality to fetch data from the database and whenever we need to get the data, we just have to call the function.
What a framework can do?
A framework simplifies the process of creating web applications. So how it does that, suppose a user is creating a web application from the scratch, so what he will do? He will create some empty directories. Inside which he will create some basic files such as “index.html”, style.css, and every time he starts a new project, he has to start from scratch and he has to repeat the exact same process for every new project. Here the framework play’s its significant role and it will do this work for the users and the user just has to start from his logic, the user does not have to start from the scratch every time he creates a new project. Now user just has to focus on the big picture of the project and framework saves a lot of time for us.
The Key Difference between the Library and Framework
The main difference between library and framework lies in a term known as “IOC” which is the inverse of control. This difference is a type of technical difference that is about the flow of control.
Let’s say, when we use a predefined function or class from the library, we have full control and it is our choice to use when and where we want to use the library (or calls the function or class already available in the library). While on the other hand if we are using a framework, it is the framework that is in charge of flow. A framework allows us to plug-in our code in some places, but it calls our written code itself according to the requirements.
Let’s understand it with the help of Example of vue.js (Framework) and jQuery (Library):
Suppose we have to create a page on which we want to display the error and relevant information about that error when an error occurs. In the following example, we will click on the button and pretend that some error has occurred.
Program using the jQuery(a library)
Look at how we used jQuery. We build our program in such a way that we tell the program where we want to call it. We can understand this, going to a college library as a student and pulling a specific book off the shelf because he wants to study.
Here we are not saying that the JQuery function does not require certain inputs when we call them. However, jQuery is a library itself of those kinds of functions. We have full control.
Example 2
In following given example, we will to do the same work but this time we will use the Framework(vue.js)
Program using the vue.js( a Framework)
While using the framework, a user just has to fill up the blanks, the VUE itself is a constructor that has several certain properties. It tells about the requirements that it needed and in the backend VUE decides where and when it needs it. The VUE (a framework) just inverts the control and we plug-in our code in the VUE. The framework has control (in charge).
Some other fundamental differences between the Library and Frameworks:
No | Library | Framework |
---|---|---|
1 | A library is a group of reusable functions and classes which are used by the developers to perform several common tasks. | A framework is basically a piece of code that dictates the architecture or the structure of our project and also adds in our programs. |
2 | While using a library in the program, the user has full control when he uses the functions or classes from the Library. | In frameworks, code never called into a framework. Instead, the Framework calls you. |
3 | The Library helps in linking and the binding process | A Framework provides a standard way to develop and deploy applications |
4 | It can be incorporated seamlessly into projects that are in the developing phase. | It cannot be incorporated seamlessly into the developing process. But instead of it, we can use it when we start a new project. |
Example: The jQuery is JavaScript library that simplifies in doom manipulations. | Example: The AngularJS is one of the JavaScript’s framework for the dynamic web-applications |
In summary
The code written in both the library and the framework is written by someone else (or other developers) that helps users to perform many standard tasks in many ways. It also does not mean that a user cannot create his own library.
When users use the library in his/her program, he/ she has full control while on the other hand, if talk about the user who uses a framework, the framework has itself the full control instead of the user. Or we can say that if the user uses the framework instead of library the control of the program inverts.
While using the library in the program, user has the freedom to call and use whereever he wants to use the library in the program. In the case of a framework, the user does not have complete freedom, although in the framework user needs to plug-in its code for the specific functionality.