DEV Community

Cover image for Frameworks vs. Libraries
AidanMargo
AidanMargo

Posted on

Frameworks vs. Libraries

Developers use tools each and every day to make their jobs faster, easier, and more accessible.

React Hooks, Ruby Gems, npm packages, these are all fantastic tools that make our lives as developers easier, but there are two in particular that seem to get thrown around more than the others:

Frameworks and Libraries

The majority of developers you come across will know what a framework or a library is for their language of choice; or at least they think they do. These terms are used interchangeably all the time, and while they're related, they are most definitely not the same.

What is a Framework, and What is a Library?

Imagine you need to run a simple task, but you're going to need to do it many times over. What would you do? You're most likely thinking "make a function/functions, duh!" And you would be right!
After all, we want to make sure that our code is DRY (Don't Repeat Yourself) and easily reusable. So, lets make a couple of functions:

function getWords(str) {
   const words = str.split(' ');
   return words;
}
function createSentence(words) {
   const sentence = words.join(' ');
   return sentence;
}
Enter fullscreen mode Exit fullscreen mode

Great! Guess what? You just created a library. It's a small, largely irrelevant library, but it is one nonetheless.

A library is much more flexible in the way that we grab, place, and use our code. It allows us to use the tools it provides us how we see fit. Sort of like going to the library and pulling whatever resource you need as you right your history paper.

A framework, on the other hand, is a bit more like hiring an interior designer to do a lot of the heavy lifting for you. You may not have as much room to do what you'd like when and where you like it, but a lot of the brain power is handled by your new handy helper. Remember, a framework is NOT the same as a language!

When to use each?

Deciding when to use a framework and when to use a library will be quite clear if you're pulling apart your goal. Often times, though, the answer is both! Having an architecture set for you to build out your applications is great, since it will do a lot of the setup and organization for you. But, for those pesky instances where you need a bit more ease of use, use a library. Here's a graphic to help you out:

Framework vs Library

Examples

Here are some examples of some libraries you may see for some different languages and their uses:

  1. Python: "Pandas" - Highly optimizes data analysis when working with text, numbers, or objects

  2. Javascript: "face-api.js" - Includes well-known and loved face detection and recognition models. Great for use with node.js!

  3. Ruby: "Better_errors" - Replaces the rails error page with an error page on the web to help with gathering information on their errors.

  4. C++: "Torch" - Provides a variety of algorithms to make handling scientific and numerical operations much more quick and efficient.

Can't forget about those frameworks! Here are a few to check out:

  1. Java: Spring

  2. Javascript: Angular, React, Vue.js

  3. Python: Django

  4. Ruby: Ruby on Rails

Rails

What are some of your favorite libraries or frameworks to use on your projects and why? Is it what you learned first? Did you transition from a different framework? Share in the comments!

Discussion (0)