
Software framework vs library
Isn’t this one of the most common questions asked in interviews? Throughout my career, I’ve observed few software developers using “framework” and “library” interchangeably but they are very different. How? Let's read/review and learn…
Generally, you’ll notice that many software applications (coded in any programming language) have a lot of similarities and commonalities with a lot of standard business enterprise applications that you develop or code. Maybe the problem domain you are solving is different but it is very likely you are solving problems that are common to “most of the developers”.
What are some very common problems?
Though your focus is to add features to your project, you generally have some common things in many projects such as
- Logging
- Database connectivity
- Authentication
- Unit testing
- Web application
- and many more
A world without Frameworks and libraries
Think about a world where libraries and frameworks didn’t exist and imagine you have to solve the above problems and need to “write every line of code yourself” i.e. “start from scratch or zero” for every project, “re-invent the wheel” every time. Can you really imagine this? Scary isn’t it?
Now think, there is an open-source project that solves some of the above problems, aren’t you a bit more relieved?
Library
Libraries exist and are used to solve common specific challenges so that developers can work less about common problems and happily focus on the primary business problem that they are trying to solve.
For example (Being a Java person :)): Log4j — is a library that solves common challenges with logging for Java projects.
Libraries are
Reusable
Have well defined API
Developer is free to decide “when” and “where” to use it, “How” to use it provided by the library documentation i.e. “You call the library”
Now imagine that many developers are solving the same problem “with the use of re-usable libraries” again and again that follow the same steps i.e. there are some specific patterns (a set of steps) that are occurring across many large scale projects ex: building web applications, mobile applications, integration applications, etc.
or simply imagine every time you develop a “web application” you need to start from zero (maintain sessions, listen to web requests) and then integrate with many libraries- Imagine doing this 10 times, 100 times, 1000 times, etc.
Now imagine there are teams who are providing this functionality with everything that you need to build large-scale applications with patterns and best practices included & awesome documentation. More relaxed isn’t it? Welcome to frameworks
Frameworks are
Reusable
Simpler but less flexible
The framework calls you — In technical terms this is called as “Inversion of control” — fancy favorite term :)
There are many examples of frameworks
- Spring framework
- VueJS
Frameworks are shipped with everything you need to build large-scale applications, they are much simpler but less flexible.
When to use what?
- Use framework — when you need to start up fast, keep it simple, follow best practices, adapt to the framework's way of doing things, lose a bit of control.
- Use libraries — To solve common independent problems and you control when and where to use the library and you need the flexibility to write your own framework.
- Use framework and library — Framework already comes OOB with many library dependencies, you have the luxury to plugin more libraries and use them confined to the framework flexibility.
- No library or framework — Write everything yourself, why would anyone do this in the 2021 year :)
Will stick around…