The difference between libraries and frameworks are frequently used interchangeably by developers.
But there is a distinction.
Both frameworks and libraries are pieces of code authored by others that are utilized to tackle common issues.
Assume you have a program in which you intend to operate with strings. You decide to make your code DRY (don't repeat yourself) by creating some reusable functions such as these:
Congratulations. You've established a library.
difference between libraries and frameworks are not magical in any way.
Both libraries and frameworks are examples of reusable code created by others. Their goal is to make ordinary issues easier to address.
I frequently use a home to represent web development topics.
Going to the library is like going to Ikea. You already have a place to live, but you need some assistance with furniture. You don't want to build your own table from start. Ikea offers you to choose and pick various items for your house. You are in command.
A framework, on the other hand, is similar to constructing a model home. You have a set of blueprints and just a few restricted options for architecture and design. Finally, the contractor and blueprint have the control. And they'll let you know when and where you may contribute.
Difference between libraries and frameworks (The Technical Distinction)
The difference between libraries and frameworks interms of technical distinction is defined by a concept known as inversion of control.
When you utilize a library, you control the application's flow. You get to decide when and where you call the library.
When you utilize a framework, the flow is controlled by the framework. It gives you several locations to put your code, but it calls the code you put in when needed.
Consider the following example, which employs jQuery (a library) and Vue.js (a framework).
Assume we wish to show an error message when an error occurs. In this example, we will press a button and pretend that an error has occurred.
Using jQuery:
Take note of how we utilize jQuery. We tell our software what we want it to be called. This is similar to going to a physical library and picking books off the shelf when we need them.
That is not to argue that jQuery functions do not require specific inputs when called, rather jQuery is a library of those functions. We are in command.
Using Vue.js
We have to fill in the blanks using Vue. The Vue constructor is a property-rich object. It tells us what it need, and then Vue determines when it requires it. Vue flips the program's control. We run our code using Vue. Vue is in command.
The difference between libraries and frameworks is whether or not there is an inversion of control.
A word on being "opinionated"
Frameworks and libraries are frequently labeled as "opinionated" or "un-opinionated."
These are all subjective words.
They seek to describe a developer's amount of flexibility while arranging their code.
Frameworks are more opinionated than non-frameworks because, by definition, inversion of control necessitates a compromise of application-design flexibility.
Again, the degree to which anything is opinionated is a matter of personal preference.
For example, I consider Angular to be a highly opinionated framework and Vue.js to be a less opinionated framework.
Finally,
- Frameworks and libraries are both pieces of code provided by others that assist you in doing common activities in a less verbose manner.
- A framework flips the program's control. It informs the developer of what they require. A library, however, does not. When and where the programmer need it, the library is called.
- The amount of flexibility a library or framework provides the developer determines how "opinionated" it is.
Thank you for your time!
Buy me a coffee + Follow me on twitter for my latest article updates
Sojin Out!
Top comments (1)
How was it developers