Live data from Hacker News

Backbone has made me a better programmer

floatleft.com

51–60 of 88 posts

Re: Backbone has made me a better programmer

#51

Earlier quoted context omitted.

@jashkenas Those sites use their own custom libraries that do about the equivalent of what the libraries I suggested use. I say this not out of any disrespect, I love backbone, but backbone doesn't provide enough to build a complex app. Does it have memory management? No. Does it provide a pub/sub pattern? No. Does it handle views/nesting subviews and layout management? No. You can roll your own library, of course, i…

> Does it have memory management? JavaScript has memory management; JavaScript has a garbage collector. If you structure an app (with any library) not to leak references, then no manual memory management or bookkeeping is needed. Not having additional memory management is a feature, not a bug. > Does it provide a pub/sub pattern? Yes. That's Backbone.Events, which is the core how models work with changes, and can be…

  If you structure an app (with any library) not to leak references
But that's boilerplate.

  That's Backbone.Events, which is the core how models work with changes, and can be mixed in to any object.
But it's messy out of the box for other parts of your app without boilerplate. You need to structure your events somehow. It doesn't take much code and the libraries that I recommend are very small.

I don't think Backbone necessarily needs more features. It's great for certain sites that uses Backbone in limited ways. I'm talking about making an entire website end to end in Backbone, something that most of your examples do not try to do. But if you're making a whole app in backbone, not just a feature or a widget, something with many many routes and regions that swap nested views constantly, you'll need a bigger library.

So, backbone alone is fine for apps that's mostly traditional / server based, with some client side features. If the entire app is built in backbone then you'll want to build on top of it. There are many many frameworks popping up around Backbone and they should be supported by Backbone. Developers clearly need them or else there wouldn't be so many of them.

Re: Backbone has made me a better programmer

#52
post #22

I didn't really like backbone at all. It was a pain. It didn't offer anything to help you build complex UI. I had to use backbone to build a mildly complicated UI - not so complex, mind you, just something that's supposed to be somewhat interactive. Backbone was no help at all. Its "views" don't really offer anything. Just about 2 weeks ago I discovered knockout.js, and I felt stupid for spending days building someth…

I've built moderately sized applications in both angular.js and backbone, backbone is much more pleasant to work with if only for the fact that everything is obvious, even if that requires you to do more development legwork and thinking about your application structure. (this is a feature, not a bug)

Angular.js data bindings are great and things like ng-repeat are neat until you start to step outside of the bounds of the angular garden.

Want to fetch data yourself and not use the angular resource plugin? (The resource plugin restricts the shape of data you can return from your server, i.e. every resource.get() request must only return a single object, if you want to receive an array you need to use .query() ). If you want to use jQuery for ajax, for instance, you lose all data bindings because vanilla javascript doesn't have the angular secret sauce! edit: angular provides utilities to alleviate this issue, addressed in comment below.

Well that's fine maybe there's an event somewhere you can hook into and trigger off of, right? Try to find this in the docs, I dare you! If this doesn't demonstrate the incidental complexity caused by using a tool like angular, consider the documentation for backbone and angular, or either projects source for that matter. You can read backbone's source in an afternoon, I couldn't say the same for angular (or ember, or knockout). Because of this I can be confident backbone is largely bug free, I absolutely can't say the same about larger projects like angular.

Angular.js is meant to have a low barrier of entry, but because of this the developer interface is a thin facade on top of astonishingly complex internals. Contrast this to backbone which provides a simple and solid base for your application, providing freedom and foundation rather than a cookie cutter solution.

When I consider the trade-offs between client-side tools for structuring applications backbone consistently comes out on top.

Re: Backbone has made me a better programmer

#53
post #52
post #22

I didn't really like backbone at all. It was a pain. It didn't offer anything to help you build complex UI. I had to use backbone to build a mildly complicated UI - not so complex, mind you, just something that's supposed to be somewhat interactive. Backbone was no help at all. Its "views" don't really offer anything. Just about 2 weeks ago I discovered knockout.js, and I felt stupid for spending days building someth…

I've built moderately sized applications in both angular.js and backbone, backbone is much more pleasant to work with if only for the fact that everything is obvious , even if that requires you to do more development legwork and thinking about your application structure. (this is a feature, not a bug) Angular.js data bindings are great and things like ng-repeat are neat until you start to step outside of the bounds o…

You raise valid points about Angular's complexity and lack of documentation.

This is why I also mentioned knockout.js

Knockout is more explicit than Angular, it's well documented, and the tutorials are just amazing.

I used to be in the "dynamic" crowd, but now I'm starting to lean towards the "explicit is better than implicit" philosophy, so I'm somewhat torn between Angular and Knockout. I'm choosing angular - like you said - for the low barrier of entry but if it turns out to be complicated I will probably switch to Knockout.js

However, I don't see any reason why I should use Backbone. What exactly does it provide? I don't see it providing anything useful to me.

Re: Backbone has made me a better programmer

#55

Earlier quoted context omitted.

Something doesn't have to be wrong to be bad learning material. That code is chock full of unconventional js. For example, why they declare their objects like this: var Typeahead = ... Typeahead.prototype = { constructor: Typeahead ... rather than the usual function Typeahead() { ... Typeahead.prototype = { ... is a mystery to me.

I'm not sure why they are prefixing the initial plugin with a `!`, but if it's the same as using a `(` then would the reason they are using `var Typeahead = ...` is to keep that method scoped to just this plugin and not global as `function Typeahead` would be doing? I'm kind of ignorant at the moment of proper best practices of js, but eager to learn more, so if you could explain to me why one is better than the othe…

No, the ! is to turn the function into an expression, and thus guarantee that it is executed. It is meant to protect against concatenating with JavaScript that is missing a semi-colon at the end of its file. This is extreme minutiae and why I said you shouldn't use that code to learn.

Re: Backbone has made me a better programmer

#56
post #53
post #52

Earlier quoted context omitted.

I've built moderately sized applications in both angular.js and backbone, backbone is much more pleasant to work with if only for the fact that everything is obvious , even if that requires you to do more development legwork and thinking about your application structure. (this is a feature, not a bug) Angular.js data bindings are great and things like ng-repeat are neat until you start to step outside of the bounds o…

You raise valid points about Angular's complexity and lack of documentation. This is why I also mentioned knockout.js Knockout is more explicit than Angular, it's well documented, and the tutorials are just amazing. I used to be in the "dynamic" crowd, but now I'm starting to lean towards the "explicit is better than implicit" philosophy, so I'm somewhat torn between Angular and Knockout. I'm choosing angular - like…

I recommend checking out http://blog.stevensanderson.com/2012/08/01/rich-javascript-a... for a more in depth exploration of the trade-offs between the popular client-side architecture tools.

I can only speak of my personal experience with these tools, and I've only tinkered with knockout (though we do use it for one of our tools internally, and the developer of that project gave it glowing reviews). I would recommend using the tool that is the closest to your development style.

If you like opinionated frameworks that make it as easy as possible to do the most common tasks (like rails), maybe you'd enjoy something like ember.js (or knockout). For me the style closest to home is the ability to plug in My Favorite Solution to each particular problem as it arises.

A primary offering from backbone then is a simple structure for plugging all these previously disparate tools together, the serverside corollary to this is something like python's Flask or ruby's Sinatra where it comes with only a simple routing base and ways to plug your own components in.

Want to use your own templating library? Easy. Want to use your custom persistence style? No problem. Backbone isn't going to make these choices for you, you will need to make them yourself.

This may or may not be the right choice for you, just investigate and make the choice that makes the most sense for you !

Re: Backbone has made me a better programmer

#57
post #43
post #35

Earlier quoted context omitted.

Could you be more specific? What was Backbone not doing that Angular does?

Nested views and automatic view updates. How would you display a list of items in backbone? What do you do when an element is removed/added? How do you update a view when an element changes? It's a lot of grunt manual repetitive work. In Knockout and Angular, it's all automatic. Related: forms.

>How would you display a list of items in backbone? What do you do when an element is removed/added?

Collections

>How do you update a view when an element changes?

Model/View binding.

I didn't think it was bad and the only issue I had was when your views broke the hierarchical nesting. I see no solutions to that problem in Angular. Was curious if your problem was something similar.

Re: Backbone has made me a better programmer

#58
post #52
post #22

I didn't really like backbone at all. It was a pain. It didn't offer anything to help you build complex UI. I had to use backbone to build a mildly complicated UI - not so complex, mind you, just something that's supposed to be somewhat interactive. Backbone was no help at all. Its "views" don't really offer anything. Just about 2 weeks ago I discovered knockout.js, and I felt stupid for spending days building someth…

I've built moderately sized applications in both angular.js and backbone, backbone is much more pleasant to work with if only for the fact that everything is obvious , even if that requires you to do more development legwork and thinking about your application structure. (this is a feature, not a bug) Angular.js data bindings are great and things like ng-repeat are neat until you start to step outside of the bounds o…

This is my concern after looking at and playing with Angular a little bit.

Re: Backbone has made me a better programmer

#59
post #37

When we started using Backbone it was good for awhile until there was so much code duplication all over the place. We decided to build a small declarative API on top of backbone that allows us to easily compose views by mixing in common functionality. It looks something like this: AlbumsView = bQuery.view() .set("el", "#albums-view") .init((opts={})-> @readOnly = opts.readOnly or no @app = opts.app ) .use(Mixins.bq.i…

What's the point of this excessive chaining? I use CoffeeScript a lot, but your code looks unreadable to me.

Re: Backbone has made me a better programmer

#60
post #37

When we started using Backbone it was good for awhile until there was so much code duplication all over the place. We decided to build a small declarative API on top of backbone that allows us to easily compose views by mixing in common functionality. It looks something like this: AlbumsView = bQuery.view() .set("el", "#albums-view") .init((opts={})-> @readOnly = opts.readOnly or no @app = opts.app ) .use(Mixins.bq.i…

What's the point of this excessive chaining? I use CoffeeScript a lot, but your code looks unreadable to me.

Chained method calls is analogous to function composition from bQueryView to bQueryView. You could write it this way if you don't like the look of it syntactically:

    bqView = bQuery.view()
    bqView.set(...)
    bqView.on(...)
    MyBackboneView = bqView.make()
Post reply on HN