Live data from Hacker News

Backbone has made me a better programmer

floatleft.com

31–40 of 88 posts

Re: Backbone has made me a better programmer

#31
I'm making my way through Jeffery Way's fantastic jQuery series. This looks similar to a Publish/Subscribe concept, also jQuery deferreds are apparently another good way to avoid putting too much code into a success callback.

Re: Backbone has made me a better programmer

#32
post #24

Earlier quoted context omitted.

Yes! Not to hijack this thread but I hated building web interfaces with javascript, struggling with cross-browser support for anything remotely non-standard. We've been using Angular.js for the last month to build a very beautiful, complex interface and I'm loving every minute of it. As long as the framework doesn't change too drastically over time I know we'll be able to keep what we've built for its 2-3 year lifeti…

Angular.js doesn't really solve the hard parts of writing web applications either. The hard part is structure. Not data binding. I don't need a framework to automatically update an for me, input.value = val isn't costing me sleep at night. What we need to make web applications easier are equivalents to things like UIPageViewController in iOS or Activities in Android. Real views that do real things. It seems that JS f…

I disagree. The hard part is nesting views/widgets, and these are very annoying to maintain manually.

Knockout.js provides a "foreach" binding, and Angular provides ng-repeat. These are good solutions that automatically handle nested-views in an efficient way.

Re: Backbone has made me a better programmer

#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 than a wild goose chase through a dozen different places in the code (and a cascade of subsequent triggers).

Re: Backbone has made me a better programmer

#34
post #24
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…

Yes! Not to hijack this thread but I hated building web interfaces with javascript, struggling with cross-browser support for anything remotely non-standard. We've been using Angular.js for the last month to build a very beautiful, complex interface and I'm loving every minute of it. As long as the framework doesn't change too drastically over time I know we'll be able to keep what we've built for its 2-3 year lifeti…

Do you use CoffeeScript with Angular? I am curious if that combo works well.

Re: Backbone has made me a better programmer

#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?

Re: Backbone has made me a better programmer

#36
I'm really glad that Backbone has helped you become a better programmer; that's great!

But it's worth nothing that this is really a trickle down effect from the creators and maintainers of Backbone making use of great design patterns and using effective programming practices. We should all strive to learn from great code in many languages using the design patterns and practices of many libraries :)

*edit: typo

Re: Backbone has made me a better programmer

#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.init('albums'))
      .use(Mixins.bq.collection
        tag: "#album-list"
        createView: (m) ->
          AlbumView = Views.AlbumView(readOnly: @readOnly)
          new AlbumView { model: m, app: @app }
      )
      .use(Mixins.bq.filterable
        pred: (album, ftext) -> album.get('title').indexOf(ftext) is 0
        filterTag: "#filter"
        collectionTag: "#album-list"
      )
      .on("click #addNew", ->
        @collection.create
          title: "New Album"
          type: "Album"
      )
      .make()
For example, the Mixins.bq.collection plugin abstracts away the common task of adding and removing subviews when new things are added the collection. The filterable plugin abstracts away the common task of filtering collections. Our custom init plugin sets up all the events common to all of our views. In the end make() just returns a BackboneView with all the events set up properly. It has saved us so much time we figure people may actually want to use this as well, we just have to write the documentation and some plugins now :)

https://github.com/jb55/bquery

Re: Backbone has made me a better programmer

#38
post #34
post #24

Earlier quoted context omitted.

Yes! Not to hijack this thread but I hated building web interfaces with javascript, struggling with cross-browser support for anything remotely non-standard. We've been using Angular.js for the last month to build a very beautiful, complex interface and I'm loving every minute of it. As long as the framework doesn't change too drastically over time I know we'll be able to keep what we've built for its 2-3 year lifeti…

Do you use CoffeeScript with Angular? I am curious if that combo works well.

Not at this stage but there are a lot of people using it successfully according to the comments on the (very active and informative) mailing list.

Re: Backbone has made me a better programmer

#39
post #14

Earlier quoted context omitted.

I also agree, although instead of Backbone I recently found that Twitter Bootstrap's javascript files offer similar insights as to how to structure code in an javascript-style object oriented manner. For example: https://github.com/twitter/bootstrap/blob/master/js/bootstra...

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.

Re: Backbone has made me a better programmer

#40
post #38
post #34

Earlier quoted context omitted.

Do you use CoffeeScript with Angular? I am curious if that combo works well.

Not at this stage but there are a lot of people using it successfully according to the comments on the (very active and informative) mailing list.

thanks. good to know
Post reply on HN