Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Which MV* framework do you recommend?

Angular or Backbone?

share|improve this question
10  
I have worked with both. The major differences are outlined well in the answers, so I won't repeat any of that. I vastly prefer Angular. That said, Angular has a strange learning curve... the easy stuff is extremely easy, but more advanced use requires a bit more time to master. However once mastered, even a little, it's a much more powerful tool than Backbone, IMO. – blesh Sep 13 '12 at 3:26
54  
Is there a better place for vs questions? Even though there isn't a right-wrong answer for this, it's incredibly helpful to the software development community. – Alan Dec 3 '12 at 20:25
30  
There seems to be a lot of this vs that on stackoverflow with a lot of upvotes, seems silly just closing them without a place to put them. – Neil Jan 8 at 15:53
4  
@Neil I agree. How can it be non constructive when so many people clearly tune into it to make a choice? I would argue these kinds of posts are actually THE most constructive parts of stack. – willdanceforfun Apr 18 at 14:33
5  
Im a web designer coming to this code from scratch, and these articles and discussions by more competent professionals are so incredibly important! This is what the net is for guys - Paul Irish condones this... One group does the learning, everyone else benefits. Im really really greatful for the time the professionals put into these posts, it helps me everyday. thanks! – itsricky May 9 at 5:06
show 3 more comments

closed as not constructive by casperOne Nov 14 '12 at 21:54

As it currently stands, this question is not a good fit for our Q&A; format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

5 Answers

up vote 206 down vote accepted

I wouldn't call Backbone a MVC framework (and AFAIK even the authors don't call it MVC). It's very lightweight, which means you have to type more, but therefore might be a good fit for a broader spectrum of apps. Backbone is based on the awesome model, and observation of this model.

AngularJS is way bigger, provides a much higher level of abstraction and is very opinionated on how you should develop your app. It's a complete solution, with testing environment and philosophy behind it... That means, building an app is super fast, but it doesn't have to fit everyone nor every app.

Note, I'm a member of the AngularJS team, so this might not be objective :-D

share|improve this answer
2  
thanks for answering it may helps me lot – Ashvin Mar 3 '12 at 11:36
66  
I really like angular, but man you need to get those docs sorted out – Neil Jan 8 at 15:54
I think the Doc is ok. It is somehow like a map, not as good as GPS, but it still provides necessary detail. – maxisam Apr 18 at 5:32
6  
What is "the awesome model"? – Steven Xu May 7 at 22:33
1  
I think he's referring to Backbone.Model. – machineghost Jun 8 at 6:01

I am currently working on a major project which is currently built on top of Backbone and JQuery. My foray into angular has been for the past few days and am still getting my head around it. Coming from a Flex world, HTML and JS seem like a step back. ( Not trying to incite any kind of a debate here! But this is just my personal opinion.. ). Like the authors of Angular profess, HTML is made for static documents. Its not meant for dynamic apps. So, given the fact that Flex was built specifically for dynamic RIA's it should be easy to see the logic.

Edit :

*I ported my Backbone application to angular. The Code size went down from 5k lines of code to guess what? 750 lines. Not just that.. The code is much cleaner.. Earlier, there was a huge technical debt attached to this implementation in backbone.. Each time I had to sit with it.it took me quite a while to understand all the hooks and how the individual models and classes and views interacted together.. ..Now its a breeze.. *

Now, the chosen libraries help you. I have to admit it. Coming from writing pure old javascript/ jQuery to using Backbone has been a huge leap. Your app is now pretty well structured, thanks to the MV* division of concerns. You have views, models and templates. While Angular banks completely on data binding, Backbone has no direct way of specifying any kind of two way data-binding.

The advantage of Backbone is that its not opinionated. It has none whatsoever except for structure. It just asks you to split your app into models and views and start putting them together. Thats about it. This is advantageous in terms of separation of concerns. But thats where the buck stops in Backbone. You can of course use meta-frameworks / plugins built on top of it like Backbone LayoutManager or Backbone Marionette ( I use Marionette ). This makes creating one level higher structure than what Backbone gives you. Marionette, for example takes care of closing views and showing them. Takes care of removing events when you remove the view from the DOM etc.. This helps you to not clean up after yourself. It helps..

For a person coming from the Flex world where everything is provided to you off the box as a component and all that you need to do is include an xml ( declarative way of defining UI! ) to say specify a Data Grid or any such complex component imagine going back to div's and table's in order to specify your UI. Its like starting to code in assembler after you are writing code in say a 4th Gen Language. Its powerful but you have to write everything ( almost ! ) from scratch. Of course, you are provided some kind of higher level application components in JQuery UI. You have tabs, accordions and such basic stuff. Lets take an example... tabs. To include JQuery UI tabs in your HTML, this is what you need to do. ( Taken directly from JQuery UI site )

    <script>
    $(function() {
        $( "#tabs" ).tabs();
    });
    </script>



    <div class="demo">

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Nunc tincidunt</a></li>
        <li><a href="#tabs-2">Proin dolor</a></li>
        <li><a href="#tabs-3">Aenean lacinia</a></li>
    </ul>
    <div id="tabs-1">
        <p>first bla bla bla</p>
    </div>
    <div id="tabs-2">
        <p>sec bla bla bla</p>
    </div>
    <div id="tabs-3">
        <p>another bla bla bla</p>
        <p>bla bla bla</p>
    </div>
</div>

</div><!-- End demo -->

In Angular if you use directives you could do the same using :

<tabs>
    <pane header="First Pane">first bla bla bla</pane>
    <pane header="Second Pane">second bla bla bla</pane>
</tabs>

The beauty is that someone else would have written the JS file ( exactly as JQuery UI! but I think you can notice the difference! ), I don't know call it a plugin? call it a component? You do see how very terse your code is now?

Now this gives way for a component architecture. What do you need for developing RIA's? Yes, a Rich Component Architecture. What Angular is creating is the ability to write this architecture. Currently it has still not hit v1.0 ( though its very close to hitting that! ). But I think if you are starting a new application, I would strongly suggest you to try Angular.

Of course, Backbone gives you the ability to "extend" a model. This basically means that you are creating an object of a class called Backbone Model ( or a class derived from it..) Angular doesn't do that. It says declare variables in this scope and It will take care of all the changes to those variables.

Pitfalls currently in Angular:

Its an extremely new framework. So the number of tutorials and screencasts you are going to find is limited, which means that you have go to the source, become Neo. ( This is in comparison to Backbone which is now perhaps one of the most famous MV* framework! ).

  • If you don't understand Dependancy Injection, then there is some learning curve because it will feel like magic.

  • At the outset, writing services or directives seem non trivial. This perhaps can be attributed to its current "infancy" state. More tuts should make it easier.

  • There isnt a single library or framework out there which tells you "Don't write any DOM manipulating code in your controllers! " . This is a radical shift in thinking. So you will need some time to readjust your brain to think like this.

Pitfalls in Backbone :

  • No opinions. No opinion means that you cannot stand on the shoulder of stalwarts. If you are stupid ( or have a fear that you are ! ) you will make stupid and costly mistakes.

  • Its too generic. This is both its strength and weakness. Strength
    because now you can mould it to do anything you want. Weakness
    because wanting to make it anything means you have to write a lot of boilerplate code.

share|improve this answer
I very much appreciated this answer and your comparison. +1 – willdanceforfun Apr 18 at 14:30
Sorry, it was TL;DR 'cause I have few mins to spare, but... "The Code size went down from 5k lines of code to guess what? 750 lines"? Which code size is that? The code you've written, or the code in general? For example, if you replace 5K LoC of code you've written w/ 10K LoC the "new" framework has, do you see any (dis)advantage in that? What is the actual infrastructure & maintenance cost you pay in your case? – Azder May 10 at 7:01
@Azder : You should probably read this article nebithi.com/2012/12/27/… it summarizes the fact that the additional "size" added by the library. Also, I have been using Angular for almost a year now. There has never been an issue with it coming in my way. There is no TL;DR in either of these.. you would probably do well to read them fully :) – ganaraj May 10 at 11:48
Thanks, the TL;DR, was 'cause I was in a hurry, luckily... weekend is coming ;) – Azder May 10 at 12:36

Having worked professionally with both Backbone.js and Angular.js -- with brief usage of both Knockout.js and Spine; I do have some idea of which is "Better".

I'm a huge fan of Angular.js as it lets you write very intuitive code which let's you create apps without including extra libraries; such as: jQuery, Underscore.js etc. It's purely Angular, then your scripts(s).

As the "To-Do MVC App on the Client-Side" has become the de-facto way of demonstrating a frameworks prowess; I suggest taking a look at To-Do MVC . Note the required libraries in each project and the actual code. The choice is fairly obvious!

share|improve this answer
2  
To-Do MVC is how I decided to use Angular.js. Just had to compare the code and it was obvious. – Michael Calkins Jun 4 at 15:29

Surely the argument between the two frameworks should be focused on what is the better 'MVC, MVP' part of it. Any other extra feature can be ported in via another library or framework. You don't need a testing framework with your mvc. You can load in an external one.

Angular.js

Pros: You don't have to write all the event listening and event triggering. Its automatic.

Cons:

  1. invents its own syntax which requires learning

  2. Obtrusively mixes all controller, model and view into the html. Therefore you could argue it isn't any kind of M V C framework, because they the controller, model and view are one. Removes the control from the developer.

  3. It only provides an interface between a combined M, V and C. What if you wanted a Model to subscribe to another Model but didn't want to update a view. You can't do this witn Angular.js, but you can with Backbone. It doesn't truly seperate the concerns.

  4. clutters the globl namespace with every single controller that you add.

    window.myCtr = function(){}
    window.anotherCtr = function(){}
    
  5. Javascript errors happen if you DON'T clutter the window object.

  6. It provides custom event declarations: example - <input onclick="doStuff"

    Atleast it doesn't require learning a new syntax.

Backbone.js

Pros: Truly enforces seperating concerns between model, view and controller, is lightweight, and easier to maintain or change in the future. Allows more control for the developer to handle anything. Although with control comes responsibility.

Cons: A bit clunky, always having to create both the event trigger and event listener in all all view, model, router etc, which makes for larger code and longer figuring it out writing it.

Conclusion: Do you want control, and compatibility with other frameworks? Use backbone. Do you want to write something more quickly in a language that isn't technically javascript which has extra bloat? Use Angular.js

share|improve this answer
33  
I too was a bit concerned about placing all my controllers in the global namespace when first starting with Angular. While this is how all the examples on the site show it, you can also hang controllers off your modules using the module API (docs.angularjs.org/api/angular.Module). Here's a basic fiddle representing this usage: jsfiddle.net/nfreitas/3znEu – Noah Freitas Jul 12 '12 at 15:33
+1 for the jsfiddle example – opensas Sep 7 '12 at 5:46
16  
"isn't technically JavaScript"? ... It's all JavaScript. – blesh Sep 13 '12 at 3:20
9  
Angular does not make you pollute the global namespace. Some examples and tutorials out there do it because it's concise. If you create modules via angular.module('name', ['dependencies']), you can register services, controllers, and directives on that module and leave the global namespace unchanged. – qualidafial Sep 26 '12 at 21:44
5  
@inspiraller : Can you modify your answer? Your points 3 - 5 , in Angular Cons section are COMPLETELY wrong. That is 3 out of 6 points which are totally wrong. – ganaraj May 3 at 9:57
show 3 more comments

I think they are roughly equally powerful. I suggest that you choose the one which you like better, based on your personal (or institutional) preference.

Both are a Model-View-Controller framework: MVC. My personal preference is the Model-View-View model framework: MVVM. To me, MVVM is harder to pronounce, but easier to use. MVVM is the framework behing Silverlight applications, and there is a wonderful Javascript version called KnockoutJS.

share|improve this answer
22  
I think the statement that AngularJS and Backbone.js are equally powerful is just plain wrong. AngularJS is a complete solution that includes a templating engine with 2-way data binding, dependency injection framework, various useful services like routing, a testing framework and more. Backbone is closer to what $resource service is in Angular than to the framework itself. – psyho Apr 3 '12 at 9:35
10  
Jason - AngularJS is 100% MVVM. The reason the Angular boys call it MVC, is because they are Googlers, not XAML developers. In Angular, Controllers are equivalent to ViewModels. You'll notice - there are no references to the view and zero DOM manipulation in Angular controllers. Knockout uses proxy objects for observable databinding. You will soon get tired of calling ko.observable() & ko.observableArray() to wrap any objects you want to databind. Proxies cause problems. Angular does not use proxy objects, and therefore you can databind directly to any JSON (ie, coming in from a service). – Ryan D. Hatch May 28 '12 at 11:53
4  
Jason (part 2) - Angular is also an HTML compiler... you can create new tags & attributes, just like you could create User Controls & Attached Properties in XAML. So everything becomes modular / you can create your own reusable components / controls. AngularJS supports scope inheritance, which is the equivalent to DataContext inheritance in XAML. AngularJS has a very bright future. Did I mention it has fully support for routes & deep-linking, partial views, services with dependency injection, and an excellent testing story? :) – Ryan D. Hatch May 28 '12 at 11:53
1  
Ryan, thanks for the feedback! You may notice that I wrote this answer almost one year ago. I still really enjoy MVCC, but your prediction is correct. I am getting weary of ko.observable(). – JasonSmith May 29 '12 at 0:21
5  
Agree with @RyanD.Hatch, AngularJS is MVVM, where scope is the View-Model. Honestly, we don't care about MV* names - for me, the only important thing is to separate presentation from logic, the rest is just discussion for scientist :-D – Vojta Jul 3 '12 at 20:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.