Difference Between a Library and a Framework

I’ll admit it, I’ve used these two words interchangeably when talking about a project, and wanted to help shed some light and clear up someone else’s confusion if at all possible. You may be asking if the code works, why should we care if it comes from a framework or a library? Well, when we start getting into project dependencies, there is often a bigger toll to pay when using a framework over a library. Often times a framework is the right solution, but there should be care and tact when it comes to picking and using one. Not just for the simple fact that it’s the hottest and newest framework being used. I’ve worked with some pretty large applications using Angular and when things are done correctly it works well, but there are also many ways to introduce problems if you don’t have a thorough understanding of it. For example, I recently came through cleaning up some code that I in part had written using in a Razor page in an ASP.NET MVC app. There was a way too much business logic being handled in the view which was ultimately removed and some of which placed into the controller, and in other ways just cleaned up an refactored to be cleaner in the view. But this type of thing requires experience and understanding of the tool. That is all any framework is, a tool. Use it as it is intended. You wouldn’t use a hammer to put in a screw, would you? Another thing that I’ve found along the way is that often time you don’t need a framework, especially if the app is small enough and not extremely complex, something like Angular for a web app would most likely be too complex and to many dependencies. Libraries are often times much smaller and if you only have a couple of things you need then that should be your go to.

So What’s the Difference Between a Library and a Framework?

# Why Does it Matter?
One way to think about this topic is who is calling who? If you find yourself pulling in a reference to some other code, it very often times is considered a library. Smaller portions of reusable code, which have a few set things that it takes care of and that’s it. jQuery is one example when thinking about web development. jQuery is a library that is meant to take care of some of the more repetitive aspects of using JavaScript, for example, the $ selector. You can do the same using the built-in functions of JavaScript var x = document.getElementById("div").querySelectorAll(".class.example");. Libraries tend to follow fewer rules, and leave more up to the developer to implement and create. For example, router logic within an application. This can often be handled by a custom JavaScript module and is actually pretty straightforward.

A framework, on the other hand, tends to have many more rules, and you break them at your own risk. There are specific ways that certain aspects of the application are supposed to be done. This is in an attempt to leave the more detailed aspect of the application to the developer, and the more common aspects of the application are left up to the framework to handle, for example, data-binding in MVVM architecture.

Think about something like angular’s routing module, if you wanted to change the behavior of this you could, however, it would be quite a bit of work to do, and still wouldn’t necessarily be as functional as what angular is handing you out of the box.

As always I hope you found this useful after all words have definitions and I hope this cleared things up to some degree. Cheers!

Next On FoC

Goals And Why They Are Important As A Developer

Goals And Why They Are Important As A Developer
Previously On FoC

Review of ‘Grokking Algorithms’

Review of ‘Grokking Algorithms’