Library vs. Framework
In the world of software and app development, there are a vast array of words and phrases that are often confusing. For example, “Library” and “framework” are two terms that are commonly used interchangeably by developers. And although they are related and help perform various tasks during the app development process, they have some differences. Basically, libraries and frameworks are reusable codes that are written by someone else to help software developers solve common programming problems in a less complicated way. Although they perform different functions, they exude some distinctions. In this write-up, we’ll try to explain the main differences between a library and framework and show you why this debate is valid.
Library
A library refers to a set of non-volatile resources such as helper functions/modules/objects used by developers to complete specific functionalities. They include things like configuration data, pre-written code, message templates, and documentation, among others. Libraries are designed to assist programmers in building cutting-edge software by simplifying some part of the coding process. They tend to focus on a specific area of application development or solve a particular programming problem.
Let’s take the analogy of baking a cake to help you understand what a library is:
If you are looking to bake a cake for your upcoming birthday, you need to have all the ingredients ready. However, since you don’t grow things such as strawberry at home, you must get it from the stores (library). And during the whole process of baking (programming), you will have total control until you have your fully cooked cake (program).
For example, if you want to find the last index of a character string, you don’t need to build code from scratch to help you do this. You can find a library with a method named findLastIndex(char) and make the call straight away and get the characters whose position you need to see as a parameter in the function call.
Framework
A framework is an abstraction that boasts pre-defined or unimplemented functions/objects that help developers create custom applications. It provides you with a standard means of creating and deploying applications in a universal and pre-defined software environment by offering particular functionalities as part of a bigger software platform. Unlike libraries, which are designed to solve specific problems or add a particular feature to a program, frameworks offer something more generic and reusable. A framework can encompass everything you use in application development.
In short, a framework is a skeleton that boasts pre-written codes that help developers build top-tier applications. Some examples include the Plug-in manager, web application system, and GUI system, among many others.
Let’s go back to the same analogy of baking a cake:
When it comes to a framework, you get your cake by purchasing it from a bakery. And although you’ll not be involved in the baking, you can still decide some of the things you want, such as color, design, and flavor. However, unlike in the situation where you baked the cake yourself (library), and the had total control of the entire baking process (program development process), in this case, this situation will be controlled by the bakery (framework)
Frameworks
Main Differences between a Library vs. Framework
Inversion of Control
The primary difference between a library and a framework is the “inversion Control.” Simply put, this refers to who is in control of the programming process.
With a code library, the developer can make a call to the library whenever they want. However, with a framework, the developer is fully incorporated in its workflow. Therefore, rather than the developer is in control of the entire programming process, it is controlled by the framework.
In simple terms, libraries ask you to call them to accomplish a task, while frameworks are the ones that will call you to get the job done.
In libraries, you simply call them. Example:
str = "Geeks.ForGeeks" var pos = str.lastIndexOf("."); // simply calling function of string library
With frameworks, they call you. Example:
$(document.ready(){ // this call will be done by the jquery // framework when document will be ready. function() { /* your code */ // our implementation inside the framework's function } });
Due to the inversion control, frameworks are more opinionated and are also responsible for a lot of decisions in the software development process. It can decide how the code is written, files location, and can even give names to the said files. Due to its nature, a framework can do so much more for developers.
Code Modification
Libraries come with codes that are centered toward a particular program or solve a specific program development problem. As such, they require that developers add more systems that have to be deleted as the development process progresses. However, even though frameworks generate new codes for a developer, the codes can’t be changed or modified later.
Therefore, unlike in libraries, in frameworks, you won’t have to worry about changing or deleting pre-written codes since they are non-modifiable.
Leave a Reply