News for hackers. Stuff that matters.
Re:Spine -- A lightweight framework for building JavaScript ... by napkindrawing on Monday April 18, 2011 @12:58PM (#2459732)
As I'm currently building a Serious Application in Backbone (dozens of Models, dozens of Views, a dozen Controllers), the differences between Spine & Backbone to me seem to come down to:

Spine does class/inheritance closer to the "JavaScript" way where properties are resolved correctly at runtime, Backbone seems a little more hackish in this area IIRC (+1 Spine).

Spine seems to have given up the separation between Controller & View. Backbone has a great separation here that has been a great aid to me in refactoring a large application. (+1 Backbone)

Backbone treats collections of Models (Backbone.Collection) as proper first-class citizens. Collections can receive & emit their own events, handle their own serialization/fetching, and make use of all Underscore.js methods (+1 Backbone)

Other than that they seem pretty similar to me. So my verdict: Spine +1, Backbone +2 :)

Re:Spine -- A lightweight framework for building JavaScript ... by jashkenas on Monday April 18, 2011 @01:56PM (#2459974)

    > Spine does class/inheritance closer to the "JavaScript" way [...]
Nope. See later on in this thread. Backbone uses constructor functions and prototypes, Spine uses Object.create. Both approaches have properties resolved correctly at runtime.

    > Spine seems to have given up the separation between Controller & View.
Nope. Spine Controllers == Backbone Views. Spine doesn't have an equivalent notion to Backbone Controllers (although if one were added, I'd imagine it would be called a Router).
Re:Spine -- A lightweight framework for building JavaScript ... by frekw on Monday April 18, 2011 @01:37PM (#2459899)
I actually think that Spine seems to implement more sane controllers than Backbone (but I never really liked Backbone's way of doing it in the first place).

Controllers are supposed to coordinate the interactions between views and models by propagating changes and events between the two.

For example, if you had a todosController responsible for controlling a collection of views, there isn't really a clean way (in my opinion) to utilize it from two independent Backbone views without passing the controller through to the view (which makes the view depend on the controller). By handling events in the controller instead of in the view, you remove this dependency (which is also similar to my perception of Cocoa's delegates/SproutCore's bindings, but I may be wrong).

Both Spine's and Backbone's view layer consists of rendering templates to the DOM. To me, a "proper" view layer would include things like positioning and both frameworks seem to utilize CSS to do this, for the most part.

I think of Backbone's controllers as a poor man's State chart, without any enter or exit callbacks (e.g going from "#/" to "#/todos" should trigger a callback that states that I will exit the state "#/", so I can do necessary cleanup).

Re:Spine -- A lightweight framework for building JavaScript ... by manlon on Monday April 18, 2011 @03:20PM (#2460267)
This is true, but because Backbone made a poor naming choice. Backbone Views are what one normally thinks of as "controllers" (coordinating presentation and models), and the view/presentation layer is not handled by Backbone per se but by something like Underscore templating. Backbone Controllers really are just some helpers to deal with URL hashes.

In my experience Backbone Views become the "top level" of a client-side app, but that is appropriate because they encapsulate controller logic.

Re:Spine -- A lightweight framework for building JavaScript ... by frekw on Monday April 18, 2011 @03:46PM (#2460343)
Yeah, I'm aware of that, but from my experience the code can end up uglier than it needs to be, either because you need to pass through proxying views further down the chain, or need to duplicate functionality.

I guess I just dislike the convention of interacting directly with collections from places where it shouldn't be done, e.g a todoView removing its own Todo from the collection (hence the risk of duplicating functionality throughout your code), instead of asking a proxying controller to do it. I think this is the reason as to why I've seen a lot of Backbone code where a reference in to the view is stored in the model itself (e.g http://documentcloud.github.com/backbone/docs/todos.html), which disgusts me since it completely misses the point of MVC.

Also, events passing feels more complicated than it would need to be (even if you can always include Backbone.Event).

Re:Spine -- A lightweight framework for building JavaScript ... by netghost on Monday April 18, 2011 @11:06AM (#2459333)
Seems neat, but it would have been nice to differentiate itself from backbone a little more upfront. The sites even look similar.

The key architectural difference seems to be that the ui is updated before the server responds, which is great in a single user situation, but can get pretty inconsistant once you're in a multi user app.

I do have to say that I like the patterns section at the end, it's always good to see a prescription for how you would use a library or framework.

Re:Spine -- A lightweight framework for building JavaScript ... by jashkenas on Monday April 18, 2011 @11:09AM (#2459344)
That's actually not an architectural difference. In Backbone, when you call .save(), the attributes update instantly, and the changes are synced to the server asynchronously.
Re:Spine -- A lightweight framework for building JavaScript ... by netghost on Monday April 18, 2011 @12:08PM (#2459551)
That was the main difference pointed out in the documentation. I guess I'd have to try it out to see how it differs in practice.
Re:Spine -- A lightweight framework for building JavaScript ... by secoif on Monday April 18, 2011 @10:34PM (#2461463)
You can create new Models independent of the Collection and they will sync to the server asynchronously when you Collection#add() them, but note that all of the Backbone events ('add','success', etc) are triggered in response to the server. It'd be nice if this was more clear, and perhaps Backbone could trigger additional events based solely on clientside actions...
Re:Spine -- A lightweight framework for building JavaScript ... by armandososa on Tuesday April 19, 2011 @12:03AM (#2461579)

  Seems neat, but it would have been nice to differentiate itself from backbone a little more upfront. The sites even look similar.
I agree. For a moment I thought it was a parody.
Re:Spine -- A lightweight framework for building JavaScript ... by probst on Wednesday April 20, 2011 @07:22AM (#2466136)
So did I! I thought it was a spoof of backbone although I couldn't really understand what the reason for the parody was, so I kept on reading to see what it was all about. Even the name suggests it is a backbone "clone".

Edit: Upon reading more about it, it sounds like a really nice framework. A shame it is branded so similarly to backbone which is bound to result in people fighting about which is better, spine or backbone, instead of seeing it for its own merits.

Re:Spine -- A lightweight framework for building JavaScript ... by armandososa on Wednesday April 20, 2011 @11:39PM (#2469370)
Yeah, The name makes it fell kinda like those "php on tracks" rails spin-offs.

But it's definitely on my list of nice things to try.

Re:Spine -- A lightweight framework for building JavaScript ... by flippyhead on Monday April 18, 2011 @11:39AM (#2459448)
Yeah, my very initial reaction was that this must be a joke of some kind -- I see that it's not -- but boy it seems so similar on the surface
Re:Spine -- A lightweight framework for building JavaScript ... by beseku on Monday April 18, 2011 @11:12AM (#2459356)
I'll be honest, it's an MVC JS framework centred around jQuery or Zepto. If I'm familiar with Backbone, what is going to drag me over to this - the size/number of lines of code isn't, thats for sure.

Javascript frameworks are making all of the mistakes that PHP frameworks did, no differentiation and promoting fragmentation. Backbone is up on Github so would it not have been more constructive to fork it and create one great product, not two less great products?

Re:Spine -- A lightweight framework for building JavaScript ... by jashkenas on Monday April 18, 2011 @11:20AM (#2459379)
As in the general economy ... competition between similar open-source projects is good for developers. Spine provides an alternative way of accomplishing the same goals as Backbone, written in a different style. I'm sure there's lots that both projects can learn/steal/share with one another.

Open source isn't a zero-sum game, the more you share, the more you have to give away.

Re:Spine -- A lightweight framework for building JavaScript ... by collypops on Monday April 18, 2011 @11:23AM (#2459395)
That's what we all sign up for. Some share more than most, which I'm sure many have/will thank you for!
Re:Spine -- A lightweight framework for building JavaScript ... by collypops on Monday April 18, 2011 @11:17AM (#2459373)
Backbone doesn't become any less great because a similar project has appeared. If we are to believe the claims of the creator, Spine is fundamentally different from Backbone, so I dont think a fork would have sufficed.
Re:Spine -- A lightweight framework for building JavaScript ... by beseku on Monday April 18, 2011 @10:21PM (#2461437)
I disagree - The more people work with something, the more it can be refined. If you read through the Issues page on Github for Backbone, there are 100s of comments, suggestions and bug fixes, all helping to improve the code and make a better framework.

By introducing a too-similar competitor, (in general, not necessarily Spine) you risk fragmenting the above, which leads to many okay projects, not one great projects.

Re:Spine -- A lightweight framework for building JavaScript ... by collypops on Tuesday April 19, 2011 @12:20AM (#2461608)
The point I was making was that Spine isn't a refinement. It may look the same on the surface, but it has some very different ideas about what a Controller is, amongst other concepts.

It's unreasonable to suggest that anyone who has an idea for a project simply abandon it because someone's already working on something similar. It's also unreasonable to suggest that if they do end up writing something really cool that touches on a few concepts of an existing project, that they should keep it to themselves.

Re:Spine -- A lightweight framework for building JavaScript ... by Tycho on Monday April 18, 2011 @12:50PM (#2459697)
I found the documentation for Spine much better than Backbone, or else it was just designed in a more intuitive way. Either way I wanted to use Backbone a while back, but kinda gave up on it.
Re:Spine -- A lightweight framework for building JavaScript ... by seats on Monday April 18, 2011 @11:50AM (#2459481)
The number of js frameworks popping up is kind of crazy. Clearly tons of overlap between them all. It kind of makes me want to not choose one and wait for tech natural selection to whittle the options down and hopefully along the way the best elements of each are demonstrated and incorporated into the few winners.
Re:Spine -- A lightweight framework for building JavaScript ... by msy on Monday April 18, 2011 @12:08PM (#2459546)
To a large degree that's what Ender.js is trying to do. Whether it'll succeed or not remains to be seen.
Re:Spine -- A lightweight framework for building JavaScript ... by joshontheweb on Tuesday April 19, 2011 @04:08AM (#2461980)
I just don't see Ender.js pulling it off. Mostly it is the use of klass that puts me off. I much prefer the pure prototypal style of backbone.
Re:Spine -- A lightweight framework for building JavaScript ... by reustle on Monday April 18, 2011 @11:33AM (#2459432)
How funny, I'm working on Vertebrae.js, a JavaScript MVC framework.
Re:Spine -- A lightweight framework for building JavaScript ... by lucisferre on Monday April 18, 2011 @11:41AM (#2459457)
Honestly there are so many JS MVC frameworks. I'm looking at using one in the next little while, but with so many it's going to take more effort than I'd like to pick a good one.
Re:Spine -- A lightweight framework for building JavaScript ... by jsparks on Monday April 18, 2011 @12:15PM (#2459570)
I like the approach of separating the dom events logic into its own controller.

In backbone the dom events are tied to the view which makes it more difficult to reuse the logic with other views. I've worked around this by doing pretty much the same thing as spine; i've created a dom controller from the base controller, but it's not ideal since the controller was specifically designed for hash change events.

Re:Spine -- A lightweight framework for building JavaScript ... by jashkenas on Monday April 18, 2011 @12:17PM (#2459575)
I think this just a terminology confusion. Spine Controllers == Backbone Views.

Both have DOM events, a "this.el" property, a "this.$" selector, and event delegation. The patterns of use should be the same.

Re:Spine -- A lightweight framework for building JavaScript ... by marknutter on Monday April 18, 2011 @04:45PM (#2460560)
I've been using JavascriptMVC on a large project for the last couple of months and have been loving it. I don't think it really matters what framework you go with, as long as it's not too DSL heavy and does things the JQuery way (assuming you're using JQuery). Just having something, anything, has made my life 10 times easier for building big JS apps.
Re:Spine -- A lightweight framework for building JavaScript ... by tomswift on Monday April 18, 2011 @02:40PM (#2460120)
Out of curiosity why does the Spine site look so similar to Backbone's?
Re:Spine -- A lightweight framework for building JavaScript ... by munificent on Monday April 18, 2011 @01:35PM (#2459889)
> Since Spine doesn't use constructor functions, due to limitations with prototypal inheritance, classes are instantiated with inst().

Can someone explain this to me? I've been using prototypal inheritance through Closure's goog.inherits() and never had any problem using regular object constructors.

Re:Spine -- A lightweight framework for building JavaScript ... by firefoxman1 on Monday April 25, 2011 @12:55PM (#2481943)
Maybe it's referring specifically to the "new" keyword that can cause issues if left out when creating instances. If you look at the code, Spine uses Object.create(this.prototype) for init.

This article is a great explanation on issues with prototypal inheritance http://howtonode.org/prototypical-inheritance

Re:Spine -- A lightweight framework for building JavaScript ... by pancakeman on Tuesday April 19, 2011 @05:57PM (#2464393)
Great for making UI. Still a lot of work to do all the crappy "extends" stuff, but still not bad.
Re:Spine -- A lightweight framework for building JavaScript ... by Rygu on Monday April 18, 2011 @10:39AM (#2459213)
Typo: the landing page says "Spine is a lightwork framework"
Re:Spine -- A lightweight framework for building JavaScript ... by maccman on Monday April 18, 2011 @06:34PM (#2461027)
That's intentional ;) Seriously though, thanks - all fixed.
Re:Spine -- A lightweight framework for building JavaScript ... by collypops on Monday April 18, 2011 @11:00AM (#2459309)
I'll have to have a dig around the code to see what's different from Backbone. Were you involved with this development, Jeremy?
Re:Spine -- A lightweight framework for building JavaScript ... by jashkenas on Monday April 18, 2011 @11:08AM (#2459339)
Nope -- someone just sent me the link this morning, and it was interesting to poke around the internals.
Re:Spine -- A lightweight framework for building JavaScript ... by heydenberk on Monday April 18, 2011 @02:41PM (#2460124)
It's to your great credit that you promote and engage openly with the "competition." FWIW, CoffeeScript + Backbone/Underscore/Docco is, in my opinion, the most exciting thing to happen to JavaScript since the advent of major DOM libraries, and possibly since before then.
Re:Spine -- A lightweight framework for building JavaScript ... by secoif on Tuesday April 19, 2011 @07:48PM (#2464702)
+1 to that.
Re:Spine -- A lightweight framework for building JavaScript ... by bchhun on Monday April 18, 2011 @10:55AM (#2459290)
wasn't this backbone.js ? the TODO example is the same one !!
Re:Spine -- A lightweight framework for building JavaScript ... by jashkenas on Monday April 18, 2011 @11:07AM (#2459335)
This isn't Backbone.js -- it's an alternative. Different codebase, different function names, partially overlapping API.

At the top of the FAQ, he answers some of the comparison questions: http://maccman.github.com/spine/#h-faq

The bit about it being smaller is pretty misleading (especially when comparing 2k to 3k) -- it may be 500 lines instead of 1100, but the 1100 are heavily commented, and the 500 are entirely comment-less. It also doesn't include any of the collection mapping, filtering, and aggregation functions, which contain a large part of the usefulness of Backbone when used with real models.

Re:Spine -- A lightweight framework for building JavaScript ... by jedschmidt on Monday April 18, 2011 @11:21AM (#2459384)
The size difference may be more meaningful once the hard dependency of Underscore.js is taken into account.

That said, competing so closely with an Ashkenas library is not a niche I'd want to be in...

Re:Spine -- A lightweight framework for building JavaScript ... by flippyhead on Monday April 18, 2011 @11:35AM (#2459438)
I'm curious how you respond to the differences in the Spine inheritance model and the argument they make for it:

"Spine's class implementation is one of its features that makes it stand out from the crowd. Rather than copying properties to emulate inheritance, as most libraries, Spine uses JavaScript's native prototypal inheritance. This is how inheritance should be done, and means it's dynamic, properties are resolved at runtime."

Re:Spine -- A lightweight framework for building JavaScript ... by jashkenas on Monday April 18, 2011 @11:44AM (#2459465)
Backbone uses proper prototypal inheritance ... so I'm not sure which "most libraries" he's comparing to there.

In fact, Spine doesn't use "JavaScript's native prototypal inheritance", which, if we're being honest, is the use of constructor functions with prototype properties. It uses an emulated version of Object.create:

https://github.com/maccman/spine/blob/master/spine.js#L79-11...

... which, even when natively implemented, is quite a bit slower than the real thing:

http://jsperf.com/new-vs-object-create

Re:Spine -- A lightweight framework for building JavaScript ... by bambambazooka on Monday April 18, 2011 @11:05AM (#2459329)
from the FAQ:

> Whoah - your API looks really similar to Backbone. Why should I use this instead? > Well, it's true that Spine was inspired by Backbone, an excellent library, and its controller API is very similar. However, the similarities end there. Internally the library works very differently. For example, Spine has no need for Collections, which are required for pretty much every model in Backbone. Spine provides a class library, and has very different ideas when it comes to server sync. Lastly, Spine is much simpler and half the size, go and check out the source.

Re:Spine -- A lightweight framework for building JavaScript ... by swirlee on Monday April 18, 2011 @11:04AM (#2459327)
From the FAQ:

"Well, it's true that Spine was inspired by Backbone, an excellent library, and its controller API is very similar. However, the similarities end there. Internally the library works very differently. For example, Spine has no need for Collections, which are required for pretty much every model in Backbone. Spine provides a class library, and has very different ideas when it comes to server sync. Lastly, Spine is much simpler and half the size, go and check out the source."

http://maccman.github.com/spine/#h-faq

Re:Spine -- A lightweight framework for building JavaScript ... by Frozzare on Monday April 18, 2011 @10:47AM (#2459252)
Looks interesting.
Re:Spine -- A lightweight framework for building JavaScript ... by thomasdavis on Tuesday April 19, 2011 @04:40AM (#2462021)
The only thing Spine seems to have really tackled is "Collection/Model synchronization" which in my opinion should have just been built as an extension to backbone.

Copying the website element for element and 90% of the design paradigm from backbone.js would have been semi-acceptable to me if the author elaborated more on the comparison between backbone in his FAQ.

"Lastly, Spine is much simpler and half the size, go and check out the source."

"Much simpler" seems like a huge call to make and it has been nice to see Jeremy refute all claims by spine.js thus far.

Edit: Also I don't think Backbone.js should receive any negative points for naming conventions. MVC has such a diluted definition that it barely matters how a framework chooses to implement it.