re: What's the difference between a library and a framework? VIEW POST

VIEW FULL DISCUSSION
 

Sorry, late to this particular party, but I see a lot of great and thought-out responses, but no clear consistent, general rules (although a few are close to the potentially overly simple/abstract ones I'm going to propose). It's important to get away from 'React vs X', and make this a computer science question that applies to any layer of the app.

The phrase 'plug into' is a little vague, but ultimately what it refers to is the Application Programming interface. Either you call the API to implement your code (framework), or you call the API from your implementation (library)

Building from @kayis 's definitions, I would refine it to:

  • Framework: Presents an API that can only be called from within its own context.
  • Library: Presents an API that can be called from any context.

Libraries you bring in to support your application are still libraries, RIGHT UP UNTIL you introduce state which limits the API calls to a specific context. At that point, you as the developer have created a framework out of the source libraries. It might look like every other implementation, but you can change out any of the source libraries to be unique.

The value proposition of a framework vs a library is also very different. Frameworks emphasize consistency and should be very opinionated. A library emphasizes flexibility and should be very general.

If I inject a library, I should be able to execute library.anyMethodOnItsAPI() in my code.

If I have to execute let framework = library.instantiateAllTheThings() and then after that I have to call framework.anyMethodOnItsAPI() to access the API, it's a framework.

Just my 2 pennies :D

PS: I need to stop writing novels. This post was originally just the 2 bullet points with no clarification at all. Then I started thinking about it. Then I had a giant post... then I had 2 posts. Thinking about it. I think that's where I went wrong :D

code of conduct - report abuse