Table of Contents:
A framework is a collection of components, libraries to be used for specific functionalities; they are usually extensible. Frameworks are also made up of reusable abstractions of code, that are usable through a well-defined Application Programming Interface (API).
To understand frameworks better, think of a mobile phone manufacturer, and imagine they have to manufacture every single material they use. Doing this is a lot of work, as they’d have to design the screen, battery, camera and all the other stuff that makes up a phone.
Now imagine they have to do this for every different model of phone produced monthly? The process will be grossly inefficient. To work around this, they could design the phone’s (electronic) board where other parts are mounted-on (the framework) and then outsource the screen, camera, and battery from other manufacturers.
The above metaphor is similar to what a framework helps with. Frameworks work as a scaffold that you can ‘mount’ your components on using the already provided slots.
You’ll hear the terms library and frameworks a lot, and people will often use them interchangeably. But there is a difference between both, regardless of the similarities.
Proceeding with the metaphor given early, think of a library to be the other parts that make up the phone—the outsourced ones. The mobile phone manufacturer can very well outsource all of them, including the board, and couple them together to make a mobile phone.
To bolster these points, here are the significant differences between frameworks and libraries:
- Inversion of Control
- Code Structure
Inversion of Control
A library is just a collection of classes, methods, and interfaces. Libraries allow you to plug in simple functionalities written by other developers with an exposed API that you can reuse.
For example, the utility library called Lodash makes a method like isEmpty(value) available to check for empty array/object values. Hence, you are in control of the entire process, calling the library’s methods as you wish.
But for frameworks, you don’t get to dictate the process; you give control to the framework. There are predefined rules you have to follow.
A library does not dictate a particular folder structure or a code structure for you, but a framework does. The freedom a library allows you can lead to problems later on, as a framework sometimes provides you with a skeleton or a folder structure to follow.
It is not always necessary to use a framework, but it’s one of the tools that can help you develop software better and faster. Frameworks will abstract some complexities away from you and let you focus on writing the business logic for the software, thereby saving development time.
With a framework, you won’t have to reinvent the wheel, as they are usually considered batteries included. Frameworks come with some of the standard tools you would need when writing code; for example, ExpressJS comes with a JSON parser.
A framework sometimes also enforces a pattern or standard to follow, which makes it easier to write better code with cleaner file structures.
There are a lot of advantages to using frameworks. Some of them are:
- They Reduce Development Time
- They Encourage Efficient Code Practices
- They Are Batteries Included
- They Are Reliable
They Reduce Development Time
The use of frameworks significantly reduces development time because they allow you to develop the functionality they’re made for, very fast. They abstract some complexity for you and provides a skeleton or scaffold for your app.
They Encourage Efficient Code Practices
Frameworks allow you to write efficient, readable code in an organized manner because they are usually opinionated and have a pattern or architecture for you to follow.
They Are Batteries Included
Most frameworks already give you standard functionalities that you would use out-of-the-box. For example, the Ionic Framework for mobile application development already comes with toasts, modals, buttons component, that will make mobile application development easier.
They Are Reliable
- ExpressJS: With over 45k stars to its name on Github and over 7million weekly downloads, ExpressJS is by far the most popular server-side framework for building fast, web application.
- Angular: It’s a framework built by Google, for building scalable and enterprise mobile, desktop, and feature-rich web apps. Angular has over 50k Github stars and 2million weekly downloads.
- ElectronJS: ElectronJS is a framework built for the creation of cross-platform desktop apps with the use of web technologies like HTML, CSS, and JS. It has over 75k stars on Github, and powers popular apps such as Skype, VSCode amongst others.
Technologies are created to make tasks less stressful and increase productivity. But there are pitfalls to using many technologies, and it’s the same with using frameworks.
These are some of the tradeoffs you often have to make when using a framework:
- Reduced Speed and Performance
- Chances of Security Loopholes
- Hard to Modify
- Steep Learning Curves
Reduced Speed and Performance
There are abstraction layers in the development of frameworks, and these often lead to unavoidable overhead. The overhead can lead to a reduction in the speed and performance of the framework. The good thing is that the decrease in development time often outweighs this. However, in time-critical applications, the ‘sacrifices’ made might be something to consider deeply before settling for the use of a framework.
Chances of Security Loopholes
Sometimes even the best of frameworks are victims of targeted security attacks or exploits. When this happens, all the software developed with that framework automatically becomes susceptible to those kinds of attacks. Luckily, most developers find solutions to the loopholes as soon as they are discovered.
Hard to Modify
Steep Learning Curves
Hence, knowing when to and when not to use a framework is a ‘skill’ and when you try to use one, ask yourself a few questions like:
- Can the application be developed without using one?
- Does it save time and effort?
- Does it scale?
- What is the impact?
If the answers are more of a “YES” than a “NO,” then a framework will fit in quite well.