DEV Community

Cover image for LIBRARY VS FRAMEWORK
Mince
Mince

Posted on

LIBRARY VS FRAMEWORK

So, many people get it wrong between libraries and frameworks. Today let's break it down quickly.

Libraries

Library

Libraries improve or provide a specific functionality. They solely focus on that single functionality and do not got out of spectrum. Like a library does not try to improve the whole mathematics capabilities of the programming language. It rather tries improve algebra only. In simple words a library can provide a solution to a specific problem that occurs while building an app

Example: Socket io, NumPy

Framework

Frameworks

Framework are similar yet completely different from libraries. Frameworks provide a backbone to build an entire app. They simplify the whole project building process rather than focussing on a single problem. So, they don't have a limited spectrum and they are not as perfect as libraries. In simple words, A framework acts like the whole bone system of your body providing a framework to build on

Example: Flask, Django

Example

python

As discussed, if the framework if like the whole of the bones of your body, a library is a single organ. Framework provides support while library provides functionality. This is the primary difference between libraries and frameworks

Conclusion

Hope you understand my explanation, If you didn't please tell me what you couldn't understand. If you did, can I get a heart pls.

Anyway, have a productive day ahead

Top comments (3)

Collapse
 
lucianlature profile image
Lucian Lature • Edited

The Hollywood Principle ("Don't call us, we'll call you") perfectly illustrates a key difference between libraries and frameworks:

  • Libraries: YOU call THEM. You maintain control of the program flow and decide when to use the library's functionality. Like calling an actor's agent to book them for your movie - you're in charge.

  • Frameworks: THEY call YOU. The framework controls the program flow and calls your code when needed. Like Hollywood calling actors for roles - the framework is in charge (deviq.com/principles/hollywood-pri...).

Example:

  // Library approach - You're in control
  import _ from 'lodash';
  const numbers = [1, 2, 3, 4, 5];
  // YOU decide when to call the library
  const doubled = _.map(numbers, n => n * 2);

  // Framework approach (React) - Framework is in control
  class Component extends React.Component {
    // Framework CALLS your code when it's ready
    componentDidMount() {
      // Your code here
    }
    render() {
      // Framework decides when to render
      return <div>Hello</div>;
    }
  }
Enter fullscreen mode Exit fullscreen mode

This inversion of control is why frameworks often require more upfront learning - you need to understand when and how the framework will call your code .

Collapse
 
mince profile image
Mince

That was really great explanation

Collapse
 
mince profile image
Mince

Better than mine, I reckon