DEV Community

Cover image for I learned it from an interview: Is this a library or a framework?
Maria Antonella ๐Ÿฆ‹
Maria Antonella ๐Ÿฆ‹

Posted on

I learned it from an interview: Is this a library or a framework?

I learned a lot of things I didn't know during a job interview. Today I share with you the first one: Is there a difference between library and framework? Of course there is, but I didn't know it. For me they were the same.

The first thing that we have to know is both libraries and frameworks are pieces of code written by someone else that is used to help solve common problems and helps you to write your code faster and easier.

I think developers often use the terms โ€œlibraryโ€ and โ€œframeworkโ€ interchangeably. There is a technical difference.

The technical difference between a framework and a library lies in a term called inversion of control. In other words, inversion of control defines the relationship between the code and a library or a framework.

๐Ÿ”น When you use a library, you are in the charge of the application flow. You choose when and where to call the library and use it. React is a good example of a JavaScript library.

Letโ€™s use an example of baking a cake. You are the baker. So you have control over the baking process. You have a recipe and some of the ingredients, which represent your program. However, you need to go to the supermarket to buy the rest of the ingredients, which represents a library.

๐Ÿ”น When you use a framework, the framework is in charge of the flow. It will provide you the places you can plug your code and it calls your code when needed. Angular is an example of a Javascript framework.
In this case, rather than baking the cake yourself, you go to a bakery to buy a cake. You get to choose the size, shape, and decorations, and the bakery will bake the cake for you according to your specifications. The bakery represents a framework and your customization represents your code.

A framework inverts the control of the program. It tells the developer what they need. A library doesnโ€™t. The programmer calls the library where and when they need it.

So what do you think? Did you know the difference between these two words?
What else did you learn during a job interview ?

Oldest comments (2)

Collapse
 
vanshsh profile image
Vansh Sharma

Simple and to the point thanks

Collapse
 
antoomartini profile image
Maria Antonella ๐Ÿฆ‹

Thank you !