Libraries vs Frameworks, one of the most confusing terms of programming. Library and Framework are both reusable codes written by someone else to save your time. And their purpose is the same i.e, don’t reinvent the wheel and keep your code DRY (don’t repeat yourself). Many developers use these terms interchangeably which is not good. They are different, How! We will see about that in this article.
What is a library?
Library is a collection of functions (to be more precise it is a collection of helper functions/modules/objects) for performing specific tasks only like Network protocols, compression, Data manipulation, string utilities, regular expression evaluation,etc. You can think of it as a doctor who specializes in only a single niche and performs all tasks related to that only like neurologist, dentist etc.
Few examples of libraries are python’s
- Pandas -> used for data manipulation and analysis,
- Numpy -> used for dealing with arrays and operation related to linear algebra
- Matplotlib -> Used for data visualization.
What is a framework?
Frameworks includes predefined functions/objects, API (application programming interface) and libraries. Unlike libraries frameworks are built for performing a vast variety of tasks, it offers something more generic and reusable for example Web application system, Plug-in manager, GUI system etc. Frameworks include almost everything you would require in application development. If a library is a doctor in some specific field then you can think of the framework as a Hospital full of doctors with mastered in different fields.
Few example of framework would be:
- Tensorflow -> Used in Deep learning
- Bootstrap -> it is a css framework for frontend
Libraries vs Frameworks
Library: As we discussed earlier it is a bundle of some function and classes to perform some specific tasks, and it is in our control like a developer can call them whenever they want/need any functionality of a model. Like suppose you want to drink fruit juice so you will go and buy some fruits (library) and you will create juice out of it by mixing different fruit (programming) according to your wish and it’s ready.
Framework: Framework is made up of two word Frame(predefined structure) + Work(any tasks). So, in a framework there is a predefined structure and we have limited choice to make our work accordingly to fit in that structure like suppose you have a photo frame of 1024×1024 then you have to make your photo of any size under that ratio, in order to fit into that. So, most of the decisions are made here by the framework which reduces the time and customizability of the application.
Also framework is not in our control like we don’t call them instead framework call us for example think of it as a vending machine of tea/coffee/and some fruit juice. Now you decide to drink fruit juice then what the vending machine will do is that it will call your function that he/she wants fruit juice then your code will call the fruit library to create juice. Since frameworks has a limited choice so it will create a juice with default juice like juice with only mango or something like that. However it can be modified by some changes.
Frameworks are connected with libraries through API (application programming interface), you can think of it as a waiter in a restaurant which connects chefs and customers.
How are they different?
Technically speaking, the key difference between both is the “inversion of control” also known as IOC. In simple terms, it means who is in control of the programming process. Like in a library we call any method whenever we want/required but this is not the case in framework, the control is inverted which means it calls us to complete a task. Which we already saw in the vending machine example. In short, we call the library to complete the task but the framework calls us to accomplish its task.
Both Libraries and Frameworks are meant to reduce the programmer’s time and effort by the functionality of code reusability. Libraries are focused on a narrow scope while Frameworks can perform a wide range of operations. Also, both of these are written by someone else which helps us perform some common tasks without being explicitly coded, thanks to their effort.
Note: If you find any mistake, it will be highly appreciable if you will help us in correcting it. 😀
Data Scientist with 3+ years of experience in building data-intensive applications in diverse industries. Proficient in predictive modeling, computer vision, natural language processing, data visualization etc. Aside from being a data scientist, I am also a blogger and photographer.