Before starting a project, the development team has to first decide the programming language they need to use and then a library or framework. Both a library and framework facilitate the development process. However, many people often get confused between library and framework (library vs framework).
So, which one to choose and when?
A library is collection of reusable functions, classes which depend on the language, “imported” into a program to make use of its abilities.
If you wish to write a high-level program and want to make system calls, you can use libraries rather than implementing those system calls again and again. Alternatively, libraries allow reusing the code that is already written by someone else or programmers can develop their own libraries instead of using the ones developed by others.
A framework is the foundation on which developers build applications for specific platforms.
Like libraries, frameworks are also developed by other developers. They are associated with a specific programming language. We can think of a framework as a single package consisting of shared resources, such as image files, libraries, and reference documents. Developers can modify that package as per the needs of the project.
2. How it works
The developer decides when to call the library. However, when we use a framework, the framework decides when to call the library.
3. Advantage and disadvantages
With a library:
· A library provides ready-to-use code to perform specific tasks.
· A library improves the performance of your code during compile time.
· You can modify the code of a library to make it fit right with your project. It lets you have control over the flow of code.
· You cannot extend a library, i.e., you cannot add custom functionalities to a library.
· Using multiple libraries in code may affect the performance due to dependency conflicts.
· Sometimes, libraries are vulnerable to malicious attacks.
With a framework:
· Framework provides all the shared resources, such as libraries, image files, compilers, APIs, and so on, in a single package.
· It enables developers to insert code for custom functionality without affecting the framework’s source code.
· You cannot modify the pre-written code of a framework.
· It is important to choose the right framework since it has a direct impact on the performance and scalability of your application.
· If you do not follow the prescribed guideline of a framework while developing an application, there are chances of security breaches.
Other libraries and frameworks:
Libraries: NumPy, jQuery, TensorFlow, and Mockito...
Frameworks: Django, Ruby on Rails, Flask, Laravel…
Which one to choose?
Both libraries and frameworks are used to facilitate the software development process. The major difference between a library and a framework is the Inversion of Control. When you use a library, you are responsible for controlling the flow of code, whereas, when using a framework, the framework controls the flow of code. When you want to accomplish a specific task, you can use a library.