Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialsahil khan
96 PointsLibrary And Framework
What is the difference between Library and Framework. I searched on google it says some annoying thing like "You call Library" and "Framework calls you". I didn't get that much. Please Help.
2 Answers
Dane Parchment
Treehouse Moderator 11,077 PointsOk, so I will be using the same description that was given provided to you because that is the basic fundamental difference between a library and a framework, I will just flesh it out for you.
When a library is described as You call the library what they are saying is you, still have control of your program, it's structure, and its architecture. You are just "calling" the library to add-on to your already existing application structure.. For example, JQuery is a library. When you add JQuery to your project, you don't have to fundamentally re-write your application. You can still use vanilla javascript, you don't have to structure your application any differently, and you don't have to follow any specific coding guidelines to make your application work with JQuery. All you need to do is make the relevant call to the library, hence: You call the library.
When a framework is described as The framework calls you what they are saying is, you are no longer in control of the structure, or architecture of your program. You must now adhere to the frameworks architecture, coding style, and structure for your application to work with it. Angular is an example of a framework and basically in order to write an application with it, you will need to implement specific folder structures, you will need specific files, and you will need to architect your program in a specific way in order for it to work: Think Components and Modules. As you can see it is not as simple as just calling some method from a library, you will need to fundamentally change your entire application to adhere to the framework you wish to use, hence: Framework calls you.
Hope that helps clarify things.
adefee
4,705 PointsLet's say you're building a house:
A library is like a hammer - you pick it up when you need it, put it down when you don't. If you stop using nails and use screws, you pickup a screwdriver instead. Libraries are pretty easy to swap out, upgrade, etc and are more extraneous. You use the library however you want within your application.
A framework is like the foundation - once in place, most/all of the rest of your "house" (application) will be built on top of it. The type of framework you use can affect the flow of the entire application - you build your application around the framework (inverse to a library). Many frameworks even include various libraries.
sahil khan
96 Pointssahil khan
96 PointsThanks for your help sir but what is the advantage of framework that even don't let us use our own design pattern?
Dane Parchment
Treehouse Moderator 11,077 PointsDane Parchment
Treehouse Moderator 11,077 PointsThe point of many frameworks is to alleviate those decisions for you as they are either built into the framework itself, or the framework provides the boilerplate code to implement those patterns.
This is also the reason that utilizing a framework is an important decision as it lessens the flexibility of your code's structure as most frameworks tend to be very strict. But also understand that extreme flexibility (doing everything yourself, or through multiple libraries) is also a problem as well, as it makes code maintenance an issue.
I will use React (javascript Library) and Angular (javascript framework) as examples to illustrate this:
Angular tends to get bad rap, because it is very strict in its structure, and does a whole lot of things on its own (routing, HTTP, Redux through NGRX, etc). This strictness however, makes maintenance, and jumping into a project a whole lot easier. This is because almost all Angular projects will be structured the same, making it easier to know what code is doing at a glance, and were to go to implement new features or fix bugs.
React tends to get a good rap because it is easy to learn and extremely flexible (it only covers ui, so other libraries must be imported to handle other things). Though this seems good on paper, this makes project maintenance a nightmare as you can have 4 or 5 libraries in a single project, and those libraries can differ between different projects. In other words React is flexible to a fault because it only does one thing well, you need to utilize a whole bunch of other things to create a fully functioning application, and those other things can vary so a group of React projects can all be extremely different from each other.
So, knowing when to choose a Framework over a Library is an important decision for your project, though these decisions tend to be made by your Technical Lead rather than your typical software engineer (unless you are building the project itself).
Dane Parchment
Treehouse Moderator 11,077 PointsDane Parchment
Treehouse Moderator 11,077 PointsAlso the way you used design pattern tells me that you are quite new to them, a design pattern is just a common solution to a problem faced in software engineering. A framework isn't going to inherently prevent you from using them, in fact some frameworks (like Angular) may even require you to utilize certain design patterns to write more effective code!
Using your own design patterns' isn't always a positive, so having a framework alleviate the need for that can also be good!