Live data from Hacker News

Announcing the first release of batman.js

batmanjs.org

41–50 of 78 posts

Re: Announcing the first release of batman.js

#41

Earlier quoted context omitted.

Nobody who knows CoffeeScript needs to be informed that JavaScript is more mainstream.

Perhaps not, but that doesn't necessarily imply that the use of CoffeeScript-only examples was a calculated move to reach the audience they wanted instead of whatever came to mind first. It's worth at least reminding them that JS examples might be more useful to more people and letting them decide consciously whether they care.

They use coffeescript's class inheritance. Here's the JS that compiles down to:

http://jashkenas.github.com/coffee-script/#classes

If they showed JS examples it would instantly turn everyone off. Trust me, you do NOT want to use this with JS.

Re: Announcing the first release of batman.js

#42

Earlier quoted context omitted.

In some cases (e.g. "class Box extends Batman.Object"), the corresponding JS would be much more verbose and less immediately grok-able. I think CoffeeScript is mainstream enough at this point that CoffeeScript-based documentation is a fine thing. Especially since, as they say at the top of the page, Batman.js "is written in CoffeeScript and its API is developed with CoffeeScript in mind."

> In some cases (e.g. "class Box extends Batman.Object"), the corresponding JS would be much more verbose and less immediately grok-able. True, but that just basically means that using JS with Batman.js is going to be a pain. In backbone.js you also extend their base classes, but you do it in a js-friendly way (var Widget = Backbone.Model.extend). Not that there is anything wrong with a CS framework, but they should…

For the record, the way that CoffeeScript does inheritance and the way that Backbone's "extend" does inheritance is almost literally exactly the same thing.

Both simply create an empty object to serve as the prototype (calling new without actually running your constructor), set up the prototype chain correctly, and stash a reference so that calling `super` is easier later on.

If "Child" and "Parent" are constructor functions (class objects), then the basic pattern is this:

    var ctor = function(){};
    ctor.prototype = Parent.prototype;
    Child.prototype = new ctor;
    Child.prototype.constructor = Child;
    
Fun.

Re: Announcing the first release of batman.js

#43

Earlier quoted context omitted.

The subtext is that you should learn CoffeeScript. It's an alternative syntax, not a new language. They wrote you a nice library and are giving it away under an MIT license. You don't get to pick the style they use to write the examples. That's like going to a science lecture and walking up to the speaker afterwards to say, "Hey, I think you have some great theories, but you really should lose that Australian accent…

>It's an alternative syntax Right... "alternative"... so makes sense to not give examples entirely in it unless your framework is intended solely for Coffeescript users.

Their framework is intended solely for coffeescript devs. Here's their example in javascript:

  (function() {
  var Shopify;
  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
    for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
    function ctor() { this.constructor = child; }
    ctor.prototype = parent.prototype;
    child.prototype = new ctor;
    child.__super__ = parent.prototype;
    return child;
  };
  Shopify = (function() {
    function Shopify() {
      Shopify.__super__.constructor.apply(this, arguments);
    }
    __extends(Shopify, Batman.App);
    Shopify.root('products#index');
    Shopify.resources('products');
    return Shopify;
  })();
  Shopify.Product = (function() {
    function Product() {
      Product.__super__.constructor.apply(this, arguments);
    }
    __extends(Product, Batman.Model);
    Product.persist(Batman.RestStorage);
    return Product;
  })();
  Shopify.ProductsController = (function() {
    function ProductsController() {
      ProductsController.__super__.constructor.apply(this, arguments);
    }
    __extends(ProductsController, Batman.Model);
    ProductsController.prototype.index = function() {
      return this.redirect({
        action: 'show',
        id: 1
      });
    };
    ProductsController.prototype.show = function(params) {
      return this.product = Shopify.Product.find(params.id);
    };
    return ProductsController;
  })();
}).call(this);

Re: Announcing the first release of batman.js

#44

hey Nick, Great to see it released! One thing I always find helpful is a comparison/discussion of where it fits with others in this realm. congrats, Jack

I agree, especially how it compares to express.js which seems to currently dominate app design for node.

Re: Announcing the first release of batman.js

#45

Earlier quoted context omitted.

> In some cases (e.g. "class Box extends Batman.Object"), the corresponding JS would be much more verbose and less immediately grok-able. True, but that just basically means that using JS with Batman.js is going to be a pain. In backbone.js you also extend their base classes, but you do it in a js-friendly way (var Widget = Backbone.Model.extend). Not that there is anything wrong with a CS framework, but they should…

For the record, the way that CoffeeScript does inheritance and the way that Backbone's "extend" does inheritance is almost literally exactly the same thing. Both simply create an empty object to serve as the prototype (calling new without actually running your constructor), set up the prototype chain correctly, and stash a reference so that calling `super` is easier later on. If "Child" and "Parent" are constructor f…

This is the way JS devs have been hacking inheritance for a long time. That's irrelevant though, we're not comparing CS to Backbone, we're comparing Batman.js to Backbone.

Backbone handles the messy inheritance code for you. Batman.js relies on CS for that, but a JS dev is going to have to write the inheritance code by hand. I posted the JS equivalent of their example in this thread, it's nasty.

Re: Announcing the first release of batman.js

#46

Earlier quoted context omitted.

>It's an alternative syntax Right... "alternative"... so makes sense to not give examples entirely in it unless your framework is intended solely for Coffeescript users.

Their framework is intended solely for coffeescript devs. Here's their example in javascript: (function() { var Shopify; var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__…

To be fair, that's the compiled CoffeeScript. While it certainly is still fairly readable (even writable), the JavaScript you write by hand won't have the same "compiled feel".

Re: Announcing the first release of batman.js

#47
post #46

Earlier quoted context omitted.

Their framework is intended solely for coffeescript devs. Here's their example in javascript: (function() { var Shopify; var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__…

To be fair, that's the compiled CoffeeScript. While it certainly is still fairly readable (even writable), the JavaScript you write by hand won't have the same "compiled feel".

It's readable, but any framework that requires you to recreate inheritance yourself is going to have a hard time selling to a js audience when Backbone works perfectly well (and can be written in cs just as easily).

Re: Announcing the first release of batman.js

#48

Earlier quoted context omitted.

For the record, the way that CoffeeScript does inheritance and the way that Backbone's "extend" does inheritance is almost literally exactly the same thing. Both simply create an empty object to serve as the prototype (calling new without actually running your constructor), set up the prototype chain correctly, and stash a reference so that calling `super` is easier later on. If "Child" and "Parent" are constructor f…

This is the way JS devs have been hacking inheritance for a long time. That's irrelevant though, we're not comparing CS to Backbone, we're comparing Batman.js to Backbone. Backbone handles the messy inheritance code for you. Batman.js relies on CS for that, but a JS dev is going to have to write the inheritance code by hand. I posted the JS equivalent of their example in this thread, it's nasty.

It is indeed nasty ... and for that extra nastiness, above and beyond the inheritance pattern listed above, you get:

* A subclass that inherits the parent's implementation of the constructor function, unless overridden.

* A named function for your class object, without IE scope leaks.

* A way to call super that's as easy as `super()`.

* Inheritance of the parent's own properties (unfortunately via copying).

* ... which enables helpful metaprogramming within class bodies. For example, Batman's own `event` decorator:

    use: @event (times) ->
      return false unless ...

Re: Announcing the first release of batman.js

#50
post #37
post #15

Earlier quoted context omitted.

Sure, I'll break it down: batman.js is a JavaScript framework for rich JavaScript applications. It's designed to make development as fast and as painless as possible for developers and designers while giving them lots of power. We designed everything around a number of primary goals such as convention over configuration, HTML-based views, and the principle of least surprise. This is something we're using at Shopify i…

I still don't really understand when I would consider using it. Would you use it to create some or all of Shopify? Maybe this blurb from the documentation could find its way to the hoe page: batman.js is a framework for building rich single-page browser applications. It is written in CoffeeScript and its API is developed with CoffeeScript in mind, but of course you can use plain old JavaScript too.

(Disclaimer: I work for Shopify.)

Shopify would use this to write the client-side parts. We can now save on a lot of server-side rendering of pages every time a request happens; instead we just send back JSON and Batman.js knows how to change the page accordingly.

We’re already using it internally for non-core projects like our phone support system (Batman.js + Faye + Adhearsion) – it makes for a really responsive web app that’s easy to maintain.

Expect to see this in the core Shopify product very soon :)

Post reply on HN