Framework vs Library
Before we get to the topic, I remember early in my career, a colleague had asked me “Is jQuery a framework or library”. I said library and he said “No, it’s a framework”. Since it isn’t too technical, people interpret it in their own ways, I will provide a nuanced take with my understanding.
Commonalities
- Both framework and library are just tools that perform a specific job/functionality.
- Angular, React, both focus on the view layer.
Framework
- A framework is an opinionated semi-complete or boilerplate application.
- By ‘opinionated’, it means it typically comes with pre-defined functionalities, a set of libraries, workflows etc
- e.g: Frameworks like Angular/Spring come with Dependency injection, functionalities for HTTP communication, validation etc.
- Advantages:
- Enables quicker development by allowing you to focus on the application logic.
- Enforcing best practices often helps make the application more scalable and modular.
Library
- A library handles specific functionality, but doesn’t enforce anything particular structure or set of features.
- e.g: React manages the DOM but doesn’t enforce aspects like routing, HTTP communication, or testing.
- Advantage: Provides more control and typically has a gentler learning curve
An Analogy
- Let’s say we need a masala for making Chicken Gravy
- Framework: A pre-packaged spice mix – it contains multiple ingredients (chillies, coriander seeds, etc.), with predefined proportions and ingredients.
- Library: Choosing individual spices – you get separate packets of chili powder, coriander seeds, etc. You can control the proportions, and if you don’t like one, you can swap it out for another. Hope it made sense :) Thanks for reading.