Even after spending years of your life in computer science, if you don’t know the difference between Library and Framework, believe me, you are not alone.
There are many programmers and developers out there who have already used dozens of frameworks and hundreds of libraries in their career, but when someone asks this question, they are like “Framework is a collection of many libraries” and that’s it.
This definition is not completely true. The actual difference lies in the way one calls another. In simple words, the code we write calls the library code, but in a framework, it is the framework’s code which calls our code. So, let’s take a look at both of these industry jargons in detail.
Read: Top 10 Most Useful Java Libraries For Programmers
Contents
What is a Library?
A library usually focuses on a narrow scope. It provides a set of helper functions, methods, etc which you can call in your project to achieve specific functionality. It’s basically a collection of class definitions that is written mainly to promote code reuse. There’s no need to start from scratch every time, you can easily use written by others to save time and energy.
As Library has a narrow scope, the APIs are also smaller and ultimately the project requires fewer dependencies to get things done. Suppose, Util library of Java has a reverse() method to reverse any string. Now, you don’t have to declare variables and run a loop to reverse a string, you can call sb.reverse() and that’s it.
Here, String str = “RandomText” and StringBuilder sb = new StringBuilder(str). Other examples include image manipulation, string utilities, regular expression, etc.
Also Read: Popular Python Libraries for Data Science in 2019
What is a Framework?
Frameworks are like the foundation on which developers build programs for specific platforms. These are designed to decrease the number of issues that a computer programmer faces during development.
Frameworks may have defined or undefined functions and objects which the programmer can use or overwrite to create an application. The major task of a framework is to provide a standardized code that can be applied to a variety of application projects.
If you know or have worked with C++ or Java, you can relate this concept to implementing abstract functions/methods. Frameworks have a wider scope and include almost everything required to make a custom user application. Some of the popular frameworks are Node.js, AngularJS, etc.
Also Read: 5 Best Frameworks for Desktop Application Development
Library vs Framework: The Key Difference
Both the Library and Framework play a vital role in software development. A library performs a specific or well-defined operation, whereas a framework provides a skeleton where programmers define the application content of the operation.
But when it comes to the Key difference, I would say – Inversion of Control. When we call a function or a method from a library, we are in control. But in the other case, the framework calls our code, and thus the control is inverted. In most cases, the framework only provides the concept. It’s the application’s job to further define the functionality for end-users.
I hope this article helped you understand the difference between a library and a framework. There are thousands of libraries available for almost every language, and helping programmers to reuse the code written by others. On the other hand, frameworks help them focus on development rather than issues.
3 Comments
A very nice article. Clearly explain the key differences
Pls, is react a framework or library,I get confused when I heard you say(you wrote/tag it a) framework … Correct me ?
React is a library