Skip to content

Instantly share code, notes, and snippets.

@oprearocks
Created February 25, 2015 22:08
Show Gist options
  • Save oprearocks/5fd3e83bb103da4dce8a to your computer and use it in GitHub Desktop.
Save oprearocks/5fd3e83bb103da4dce8a to your computer and use it in GitHub Desktop.
BackboneJS feedback
[BackboneJS](http://backbonejs.org/)
==============================
Philosophy
-------------
BackboneJS is a lightweight LIBRARY aimed to offer developers the ability to structure their front-end code into a more MVC-oriented way.
Description
-------------
Backbone is considered MVC, but the C stands for Collection. Unlike other frameworks (MVVM, MVWhatever), Backbone is closer to the classical MVC structure, as it offers the developer the possibility to roll their own _Controller_ and have the proper _C_ in place.
### Project types
* It is suitable for projects of all sizes, because of it's small file size, and it's small impact on performance, but from my experience, when shipping big applications built on Backbone, extra caution needs to be applied in terms of application structure (both logic and filesystem) in order for everything to work properly and be easily extensible.
### Benefits
* Easily replicate an MVC application by using Backbone.Marionette which is an abstraction layer over Backbone that removes a lot of the boilerplate code that is required for view creation and manipulation.
* Allows the use of application-level controllers
* Controllers are mostly configuration, replicating a more Rails-y workflow
* Backbone.Marionette applications have more semantic value because of the naming conventions used throughout the library.
* Backbone is easily extensible via plugins, and there's plenty of material on how to build BackboneJS plugins.
* Offers more granular control on what data is being manipulated by the application at one specific time.
### Drawbacks
* Documentation and resources might be scarce, compared to bigger frameworks.
* Two-way binding, is only available through a handful of libraries or it can be custom built
* Server sync methods also need to be (over)written by hand and
* No out-of-the-box templating — there are multiple choices but unlinke Angular's templating, for example, which goes more towards Shadow DOM and native DOM manipulation, Underscore templates for example perform RegEx, variable interpolation and DOM section replacing which triggers a lot of repaints/reflows behind the scene.
* Even though Backbone.Marionette abstracts away view handling very much, you might lack control at template level.
* Backbone has a history with zombie views (Marionette fixes this, but I don't know if it's safe to only rely on that)
### Dependencies
* Backbone has jQuery and UnderscoreJS as hard dependencies that it cannot function without.
* jQuery can be replaced with the faster, slimmer Zepto, but currently they also support custom builds so a build that uses only the essentials can be created.
* Instead of UnderscoreJS we can use LoDash which is a library that implements Underscore's methods 1-to-1, but it has better performance as it's not trying to be fool-proof.
### Final notes
The learning curve is very easy for people who already know programming, and if they know OOP, MVC and preferably JavaScript they can probably pick it up in 2-3 hours.
One tradeoff if using this library instead of an actual framework is that the community is not that big, nor influential, so there might be some issues in solving some complicated, specific business problems, that people might have not found during development and aren't documented at all.
Another tradeoff is that we don't know how long the tool is going to be maintained, if it has/will have support for ES6(which is at the door)
__Stackoverflow comparison:__
* [angular, angularjs, angular.js](http://stackoverflow.com/questions/tagged/angularjs?sort=votes&pageSize=50) — 79,822 Questions (+ approx. 30 000 in related tags)
* [backbone.js](http://stackoverflow.com/questions/tagged/backbone.js) — 17,445 Questions (+ approx. 3000 in related tags)
* [ember.js](http://stackoverflow.com/questions/tagged/ember.js) — 14,118 Questions (+ approx. 5000 in related tags)
### Reference
[backbonejs.org](backbonejs.org)
[underscorejs.org](http://underscorejs.org/)
[lodash.com](https://lodash.com/)
[stackoverflow.com/tags?tab=popular](http://stackoverflow.com/tags?tab=popular)
[jquery.com](http://jquery.com/)
[zeptojs.com](http://zeptojs.com/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment