Wednesday, April 17, 2013

a Library or a Framework?

I've heard this question asked many times: "is it a framework or a library?" and even "what is the difference?". It's quite tricky to differentiate between the two and often the difference doesn't really matter. I've heard a few concerns about using frameworks because they lock you in to their style and way of programming, but this should be seen as a good thing, not a bad one. I'll go over that later, but first - just what is the difference?

The way I like to think of it is that a framework is something you build on (decides structure) and a library is something you build with (has little influence on structure).. It's a simple distinction and one which can get a bit gray or fuzzy. The real reason is that people try to define these projects as one or the other, but what defines them as a library or a framework is how we use them.

The other issue is that we can split frameworks and libraries in to categories. Frameworks tend to span multiple categories and so they are more likely to have an impact on what other tools you can use. Here is a list of categories that libraries/frameworks work on (though it may not be exhaustive):


  • Application Layer (e.g. initialization)
  • Communication (e.g. mediator)
  • Storage (e.g. localstorage)
  • Events
  • DOM
  • UI (widgets)
  • Timing
  • Data (models)
  • Inheritance
  • Animation
and so on. It might be easier to have a look at a few libraries/frameworks and see how they fit in:

jQuery

library. Although using it can litter your code with dollar signs and many people start with it, you can just as easily pull out jQuery, put in vanilla javascript (although it will be longer) and there shouldn't be much worry.

Ember


framework. Try pulling out any ember related code and see how much of an application you have left.

AngularJS


framework. If you have a look on their website they even call it an MVW framework.

Backbone

library or framework. It depends on how you use it. Backbone can be easily added to projects and if you're just using the models then I'd call it a library because they can be easily replaced. However Backbone does also give you an events system and views and give you a way to inherit from from it's view. If you're using all this then it's become a framework because you're using these tools to build your application and they're not so easily replaced (by easily replaced I mean you can go to the backbone specific code in your project and pretty much just replace code at that point).

Closure

library & framework. Closure is a bit different. It has a library full of utility methods that are easily replaced so that part is a library. However it has dependency management and inheritance goog.ui.component which will defined how you structure your application so it's both.

Knockout

library. It gives you data binding which may influence how you structure your application but in no way controls it.

So what do you use? is it a library or a framework? 

No comments:

Post a Comment