What Is The Difference Between A Framework And A Library

Ukpa Uchechi
4 min readJul 26, 2021

--

Framework and libraries are terms that are used in software development and are sometimes used interchangeably. Until a certain point, I didn't even know they were different, you hear things like it’s not a framework it’s a library.

Before we look at their differences,
Let’s see their definitions.

What is a Library

A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined interface by which the behavior is invoked. For instance, people who want to write a higher-level program can use a library to make system calls instead of implementing those system calls over and over again.

Haha don’t be thrown off by the grammar, In simple terms, A Library is a collection of methods that solves the problem of repetition, you may have heard of the DRY(Don’t Repeat yourself) Principle, For Instance, you have a problem where you need to convert a string to a number and this occurs in like five(5) other places in your code or across different applications instead of solving this problem over and over again, you create a reusable function or method that you call whenever you encounter this same problem, woohoo you just made a library. Examples include react, omini auth, JUnit, passport js, etc

What is a Framework

According to Wikipedia a Framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software. It provides a standard way to build and deploy applications and is a universal, reusable software environment that provides particular functionality as part of a larger software platform to facilitate the development of software applications, products and solutions.

A Framework is like a boilerplate. Okay, take for example a website template, when you want to build a website and you don’t want to write basic stuff from scratch you just get a template and build on it. That’s how a framework works it creates the foundation for you to build on. In general, frameworks are created to make development faster and easier for developers, by providing needed tools, so they can focus on the main development of the application. Examples are Angular, .net, Nestjs, express, Django, Flask, Spring boot, etc

Inversion of Control
Using library or libraries, the flow of control is with the developer, that is, you have the control of when to call the library in your code for instance when you want to convert a string you will the code that will handle the conversion, but with a framework the flow of control is inverted, the framework calls your code, for example when there a request by a user the framework calls the code that will handle that request.

Functionality
A library
is usually for a specific purpose, like for instance a validation library, its only aim is to validate when you need to validate a request body, user’s input, etc you call it, A framework serves more than one purpose, it provides different tools, resources, and libraries that you can use to build your application.

Modification
You can extend a framework functionality, but you cant modify its code, oftentimes frameworks give room for it to be extended because, users may have different problems they want to solve, in other for it to be dynamic.

Let’s Look At Opinionated and UnOpinionated Frameworks

Some frameworks are more Opinionated than others. What makes them opinionated, these frameworks give a structure on how your code should look like, favor some design patterns over others, it often does more for you, comes with some pre-written codes, setups, configurations, etc, while unopinionated Framework gives you the flexibility to structure your code, set up, choose the tools you want to use, it does less for you. Take a look at express js and nest js, express is a less opinionated framework, it does not structure your code or come with pre-written codes, etc

Express js

Nest on the other hand does, structures your code, setups, configures, comes with pre-written codes, and does a lot for you.

Nest js

In conclusion, The two eliminate code repetition and make developing an application faster and easier.
Frameworks reverse the flow of control, calling your code when needed, and libraries are called by programmers when they need them.

References
https://en.wikipedia.org/wiki/Software_framework
https://en.wikipedia.org/wiki/Library

--

--

Ukpa Uchechi
Ukpa Uchechi

Written by Ukpa Uchechi

A Tech Enthusiastic and lover, who loves teaching and learning.

No responses yet