Developers often use the term "framework" and
"library" interchangeably. Are they the same or any different?
Let's check.
Both frameworks and libraries are code written by someone else that is used to help solve common problems.
A library is like going to furniture. You already have a home, but you need a bit of help with furniture. You don’t feel like making your table from scratch. From a furniture shop, you are allowed to pick and choose different things to go in your home. You are in control.
A framework is like building a model home. You have a set of blueprints and a few limited choices when it comes to architecture and design. Ultimately, the contractor and blueprint are in control. And they will let you know when and where you can provide your input.
The Technical Difference
The technical difference between a framework and library lies in a term called inversion of control (IoC).
When you use a library, you are in charge of the flow of the application. You are choosing when and where to call the library. When you use a framework, the framework is in charge of the flow. It provides some places for you to plug in your code, but it calls the code you plugged in as needed.
Library
A library provides a set of helper functions/objects/modules which your application code calls for specific functionality. Libraries typically focus on a narrow scope (e.g., strings, IO, sockets), so their API’s also tend to be smaller and require fewer dependencies. It is just a collection of class definitions. Why we need them? The reason being very simple i.e. code reuse, use the code which has already been written by other developers. Example, some library has a method named findLastIndex(char) to find the last index of a particular character in a string. We can straightaway call findLastIndex(charToFind) function of the library and pass the characters whose position we need to find as a parameter in the function call.
Framework
Framework, on the other hand, has defined open or unimplemented functions or objects which the user writes to create a custom application. (C++/Java users will understand this as it is much like implementing an abstract function). Because a framework is itself an application, it has a wider scope and includes almost everything necessary to make a user application as per his own needs. Wikipedia makes it more clear:
In summary
- Library: It performs a set of specific and well-defined operations. Examples: Network protocols, compression, image manipulation, string utilities, regular expression evaluation, math etc
- Framework: It is known to be a skeleton where the application defines the content of the operation by filling out the skeleton. Examples of frameworks: Web application system, Plug-in manager, GUI system. The framework only defines the concept but an application further defines the functionality that is useful for end-users.
- Inversion of control: When we call a method from a library, we are in control. But in framework, the control is inverted i.e. the framework calls us.
- Frameworks and libraries are both code written by someone else that helps you perform some common tasks in a less verbose way.
- A framework inverts the control of the program. It tells the developer what they need. A library doesn’t. The programmer calls the library where and when they need it.
- The degree of freedom a library or framework gives the developer will dictate how “opinionated” it is.
React or angular
ReplyDeleteDepends on project
Delete