Live data from Hacker News

Backbone has made me a better programmer

floatleft.com

41–50 of 88 posts

Re: Backbone has made me a better programmer

#41

Earlier quoted context omitted.

Please don't learn anything from that code.

Aside from the always controversy-inducing lack of semicolons and the slightly unintuitive leading bang for the IIFE, I don't really see what's wrong with this code.

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.

Re: Backbone has made me a better programmer

#42
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 would say it's because you guys are doing it wrong. Backbone is just a very bare-bones backbone for your app. As you say, views don't provide anything. In fact backbone barely helps you with organizing your code at all. It's great for making a todos app but terrible for anything stretching across multiple pages, and with more than 10 views on a page.

Let's be serious here.

DON'T USE BACKBONE TO START A NEW APP!!!

DON'T USE BACKBONE TO START A NEW APP!!!

DON'T USE BACKBONE TO START A NEW APP!!!

Use one of the higher level frameworks built around backbone.

The most flexible / clean, decoupled framework (my preference) is: https://github.com/derickbailey/backbone.marionette

If you like coffeescript: https://github.com/chaplinjs/chaplin

If you want *only good views/layout: https://github.com/tbranyen/backbone.layoutmanager

If you want modelbinding: https://github.com/mikeric/rivets

Backbone is very much bring your own module, starting with just backbone is not the way to go for an app of any reasonable size!

Re: Backbone has made me a better programmer

#43
post #35
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…

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.

Re: Backbone has made me a better programmer

#44
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 would say it's because you guys are doing it wrong. Backbone is just a very bare-bones backbone for your app. As you say, views don't provide anything. In fact backbone barely helps you with organizing your code at all. It's great for making a todos app but terrible for anything stretching across multiple pages, and with more than 10 views on a page. Let's be serious here. DON'T USE BACKBONE TO START A NEW APP!!! D…

I'm afraid that advice is about 180 degrees away from the truth.

If you look at the kinds of large scale projects that people are building with Backbone:

http://backbonejs.org/#examples

... or the new Hulu.com, from earlier this week -- I'm not aware of any of the sites on that list using any of the libraries you're recommending.

Re: Backbone has made me a better programmer

#45
post #33
post #2

I actually prefer the second (complicated) example: everything that happens on the success of the call is right there. If it were to grow more complicated than that I'd move it to its own function and perhaps break it into a few functions: not into several objects. I find firing events to be useful when I'm writing code that's not meant to be directly accessed, e.g. a jQuery plugin.

Right. What the author of the article ignores is the tradeoff you make when you spread triggered behavior all over your code. When something goes wrong, debugging is a lot more difficult and race conditions sprout up unexpectedly. Event driven, decentralized programming requires new rules and discipline in how resources are accessed. Sometimes a big ugly function where everything happens is a lot easier to deal with…

Agreed. And it doesn't have to be ugly, either.

Re: Backbone has made me a better programmer

#46

Earlier quoted context omitted.

I would say it's because you guys are doing it wrong. Backbone is just a very bare-bones backbone for your app. As you say, views don't provide anything. In fact backbone barely helps you with organizing your code at all. It's great for making a todos app but terrible for anything stretching across multiple pages, and with more than 10 views on a page. Let's be serious here. DON'T USE BACKBONE TO START A NEW APP!!! D…

I'm afraid that advice is about 180 degrees away from the truth. If you look at the kinds of large scale projects that people are building with Backbone: http://backbonejs.org/#examples ... or the new Hulu.com, from earlier this week -- I'm not aware of any of the sites on that list using any of the libraries you're recommending.

@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, it's not that hard. But you can also not reinvent the wheel and use an existing open source solution.

If you read the complaints in this thread it's mostly *backbone doesn't do enough. Backbone is great as 1 layer of abstraction, but you need more layers in order to code effectively.

Re: Backbone has made me a better programmer

#47

Earlier quoted context omitted.

I'm afraid that advice is about 180 degrees away from the truth. If you look at the kinds of large scale projects that people are building with Backbone: http://backbonejs.org/#examples ... or the new Hulu.com, from earlier this week -- I'm not aware of any of the sites on that list using any of the libraries you're recommending.

@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 mixed in to any object.

    > Does it handle views/nesting subviews and layout management? 
Right -- your UI and your HTML is your business. Not having an explicit view hierarchy or layout paradigm is part of the reason why Backbone Views can be used in the kinds of diverse environments you see in that list of examples ... from "enhanced" static pages like Pitchfork.com, to interactive SVG-based graphics like SeakGeek's stadium maps, to multiplatform hybrid web/native views like LinkedIn Mobile.

That said, if you think you've got an idea for a "layout" feature that would help with UI across the spectrum, it would make for a great pull request.

Re: Backbone has made me a better programmer

#48

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…

> > Does it have memory management?

> JavaScript has memory management; JavaScript has a garbage collector.

The problem with javascript apps is not leaking memory, it's forgetting to unbind events and/or binding events multiple times.

Angular.js and Knockout.js relieve you of this problem because they handle all the event binding so you don't have to worry about it.

Re: Backbone has made me a better programmer

#49
post #23

Unit testing will also force to decouple your code in a similar way. In the first example it is impossible test individually test all the things the code should do without worrying about everything else that is going on (e.g. you need make sure all the elements exist on the page). By moving to an event trigger like you suggest, you can then test that each listener does the correct thing independently of the others. Y…

I've been using TDD for server-side code for some time now, but I struggled with it for javascript; I thought unit testing javascript was a myth. It was only when I started using backbone that I realised that I was writing horrible, terrible code.

Re: Backbone has made me a better programmer

#50

Earlier quoted context omitted.

Aside from the always controversy-inducing lack of semicolons and the slightly unintuitive leading bang for the IIFE, I don't really see what's wrong with this code.

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 other, that'd be rad :)

Post reply on HN