Hacker News new | past | comments | ask | show | jobs | submit login

Why are the backbone.js controllers called 'views' and the views called 'templates'?



Views are not controllers. Views are more akin to presenters, or viewmodels. You are right that what is traditionally considered a "view" in the rails parlance is a template to backbone.

fwiw, Routers used to be called Controllers.


Looking at the definition of controllers here: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93cont... how are backbone.js 'views' not controllers?

Or does this logic belong in the Route.js file? I am clearly confused.

FYI.. rails didn't invent mvc; it was invented in the 70's for smalltalk.


I think we all know that by now. Backbone doesn't subscribe to neither MVC or MVP. It takes what it needs and does away with the rest. Either you like that or you don't, but that doesn't make it wrong.


I originally came very close to doing just that ... but decided to call the Backbone.View a "View" because it's usually tied very concretely to a specific DOM element. From the perspective of your application, as you're working with the object, it feels like a view.

That said, if it really bugs you, no worries:

    Backbone.Controller = Backbone.View;
Boom.


One of my co-workers comes from a strong server side MVC background; dealing with Backbone has confused him greatly as to the terminology and separation of concerns.

The break-through explanation I gave him is that Backbone views are DOM elements that are code-backed and adhere to OOP principles. They have constructors, properties, methods, etc. Ultimately, though, they are DOM elements. They can derive their content from templates, but they're still just code-backed DOM elements.

They sometimes behave as smart elements.. and sometimes they behave as controllers. Sometimes, depending on necessity, views get rendered and added to the DOM without templates at all (thus the nicety of tagName and attributes). Sometimes views necessitate a template because the result of the view is less dynamic, or merely appends more dynamic views and places them within placeholders in the template.

Point being.. They're not called controllers because they aren't controllers. They can behave as controllers, but... they're still not strictly controllers. The templates aren't called views because, although the UI is a result of the templates, they aren't always the sole source of the UI.

Backbone indeed lacks clear naming conventions if we are to stuff it in to an existing paradigm, but I have no need to do that - and I don't think you should try it either.


Sounds like Django's "MTV" naming of those concepts: http://www.djangobook.com/en/2.0/chapter05.html#the-mtv-or-m...


Yeah, I've started learning Django this week, and one of the first confusing questions I asked myself is "why are there so many templates?". Then I realized a template in Django is like a normal view in Rails or other frameworks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: