Hacker Newsnew | past | comments | ask | show | jobs | submit | Autre's commentslogin

The interesting thing here is: why do big companies don't need to keep their talents? Does bureaucracy compensate for lack of talent? And vice versa? Does this also mean that you can innovate without talent?


big companies exist to execute a well known business model. they invest in lobbyists to keep the business climate stable so they continue to execute their business model. it usually makes more sense to outsource innovation -- e.g., invest in and acquire startups.


Maybe I overlooked, but is there support for "super.method()" or something along those lines?


super is a nightmare to emulate and get "right". It has a bunch of weird edge cases you don't really want to think about.

I promote code like

    var Cat = Object.make(Animal, {
      constructor: function() {
        Animal.constructor.apply(this, arguments);
        ...
      },
      walk: function() {
        Animal.walk.apply(this, arguments);
        ...
      }
    });
Now compare:

- Animal.walk.apply(this, arguments);

- this.super.apply(this, arguments);

- this.super.walk.apply(this, arguments);

Using super doesn't fix verbosity, it only fixes hard coupling of Child class name to Super class name.

For the complexities, edge cases and performance penalties a super implementation gives, it's simply not worth fixing this hard coupling.

If you know of a super implementation that _just works_ please [Leave an answer on StackOverflow](http://stackoverflow.com/questions/8032566/emulate-super-in-...)


I've been getting along fine with nothing but util.inherits from NodeJS.

Are there any real advantages to the "set the prototype to this object" approach versus building it up by assigment?

    function Animal(legs) {
        this.legs = legs;
    }
    Animal.prototype.speed = function() {
        return legs * 10;
    }
    
    util.inherits(Dog, Animal);
    function Dog(name) {
        this.constructor.super_.call(this, 4);
        this.name = name;
    }
    
    Dog.prototype.speed = function() {
        // I don't disagree that more sugar here would be good
        return this.constructor.super_.prototype.speed.call(this) * 2;
    }


What your showing is ES3 OO sugar.

The problem I have is that the notion of a constructor function goes against prototypical OO.

In prototypical OO we just have objects and objects inherit from objects. there is no notion of a constructor function.

Also note that pd.make returns an object rather then a function.

It's simply a programming style I like, to think of my "class" object not as the constructor function but as the prototype object.

Not to mention that `x.prototype.foo = ...` is ugly.

    var Animal = {
        constructor: function () {
            this.legs = legs; 
        },
        speed: function () {
            return this.legs * 10;    
        }
    };
    
    var Dog = pd.make(Animal, {
        constructor: function (name) {
            Animal.constructor.call(this, 4);
            this.name = name;
        },
        speed: function () {
            return Animal.speed.call(this) * 2;    
        }
    });


Yeah, it gets really hairy, really quickly.

Beyond the need for calling the constructor (which I'm currently viewing it as an unnecessary hidrance [objects are already initialized]), Object.getPrototypeOf may provide a way out - but maybe not the way you intended. Have you considered it?


    Object.getPrototypeOf(Child).constructor.apply(this, arguments);
Works, but is even more verbose. However if you use Object.getPrototypeOf on this you fail the recursive problem in nest super calls. Read the stackoverflow euestion


I was deliberately excluding the constructor situation. I should have made that clearer in my previous comment. I think the way out of the constructor mess is not to require them at all.

I do think the Object.getPrototypeOf approach is feasible for methods.


the method fails for the exact same reason.

If a single method calls a super method and that method calls another super method then it fails.

    Object.getPrototypeOf(this).method
Always have one value and only one value, calling it more then once leads to infinite recursion.


Yeah, but would you be willing to read and develop, say Cassandra, in ed? I, for one, wouldn't. One more thing: would you be able to?


  If you've made changes to your profile, you may force a refresh by pointing your browser to hackerhub.org/r/yourid.


Thanks, missed that. Will put it in a post-commit hook.


Are arbitrary rss feeds recognized?

[edit:] Seems like rss, not atom feeds, are recognized.


Readability is just one click away http://www.readability.com/


Also: have a look at https://github.com/manuel/schampignon (an interpreter for a Kernel-like language)


Practically you need some desicion making control structure (cond, if) and an emulation of read/write tape (arrays)


Well actually unbounded recursion and infinite memory is what is required for turing equivalence. Conditioning can be present in a non turing complete language. I added the practically because all computers on which language models are built on are finite. It is easier to get turing completeness than to ensure you haven't accidently allowed it to sneak in - as evinced in C++ templates.

http://en.wikipedia.org/wiki/Primitive_recursive_function#Co...


The same philosophy is applied in the Seaside framework for Smalltalk. See for example [1].

[1]: http://onsmalltalk.com/page-templates-and-seaside


I don't see how Object.create goes against the grain of the lang. On the contrary, `new' was bolt on to make js look like classical oo languages. I have found, in toy and exploratory projects at least, that using variations on Object.create [1] is a nice, strong pattern, that really gets the best out of js. It certainly feels more natural than class based oo. Though, take it with a grain of salt, since I'm unable for now to provide an example backing my thesis :)

[1]: https://developer.mozilla.org/en/Differential_inheritance_in...


I would love to see an example backing your thesis, if you don't mind digging one up.

I've had this debate with folks many times before, and literally every time it comes up, they're unable to find an example of using prototypal inheritance in a style that wouldn't also be considered classical.

If you think that writing:

    var point = Object.create(Point);
... is somehow magically prototypal, while writing:

    var point = new Point;
... is unnaturally classical, I'll argue that you're missing the, ahem, point.

They're two different ways of writing the exact same pattern. And, if we're being honest with ourselves, the "Point" object in that code should rightly be called a "class": it's the abstract object that defines the shape of all points. Of course, in JavaScript, we also tend to call it the "constructor function" (which it is, technically), and sometimes, the "prototype" (because it serves in that role).


Very few examples of prototypal inheritance shows it beeing practically different from class based inheritance. If all (non-function) instance fields are assigned new values - like the Point example in the article - it is basically the same.

Prototypal inheritance makes a difference if one instance inherits field values (other than functions) from another instance. But this does not seem to be very common.

I believe one of the original use cases for prototypal inheritance were to save memory by letting GUI controls share common properties. Eg. if you had 10 buttons on the screen which all had the same color, same dimensions etc. With class based inheritance each instance would have their own copy of all properties, even if they have the same values in each instance.

I don't think that kind of optimization is relevant in modern JavaScript.


Well, I have to argue that it's not the same pattern. I think the problem is that you still like to believe that js has classes, which it doesn't: js has got objects only. That it also has constructor is an (admitted?) historical mistake. Just think of all the weird crap that goes on to make `new func()' work and produce a new object.

What is no mistake is the refreshing change of view you get when you start embracing objects and prototypal inheritance. See for example the traits library[1, 2].

[3]: Is a cursory introduction to Self, with another points example :)

[4] Contains an example of my own (heavily inspired by Self and Io). I have stitched together various internet sources to come up with `clone', an operator assisting in differential inheritance.

[1]: http://traitsjs.org/

[2]: http://code.google.com/p/es-lab/source/browse/trunk/src/trai...

[3]: http://www.cs.aau.dk/~bt/DAT5E08/MarkusKrogh1.pdf

[4]: https://gist.github.com/997910


Traits aren't incompatible with classes at all. In fact, Tom van Cutsem, the author of traits.js worked on the class proposal that's going into Harmony.

Aside from the simplicity argument, I didn't see anything in Markus's presentation that showed an advantage of prototypes. His point example is cloning a point and then immediately replacing all of the state, so there's nothing there that classes couldn't do (in less code).

Your gist (especially the color point) is an example of using prototypes in a way that's hard with classes. Fortunately, adding classes to JS won't hurt that at all. You could just as easily do:

    class Point {
      constructor(x, y) {
        public x = x;
        public y = y;
      }

      add(other) {
        return new Point(this.x + other.x, this.y + other.y);
      }
    }

    let p1 = new Point(0, 0);
    let p2 = p1.clone({
      color: '#green',
      toString: function() {
        return this.color + ': ' + uber(this).toString();
      },
    })
In other words, adding classes to JS won't take away anything already there. It just gets a really common pattern and makes it much less verbose. The idea is to pave the common path of class-like inheritance, but not to build a fence around it to keep you in.


Object.create(...) is a factory pattern. "Object" is suddenly a factory for making anything, you just supply the blueprint in the form of "Point." So to know what will happen, I need to look at Object and at Point. One strength of this pattern is when I want to handle cross-cutting concerns in the factory. For example, I can modify all objects created with aspects if I use a factory to create them. Or I could have the factory decide whether it is creating Plain Old Javascript Objects or whether each object is backed by persistent storage a'la ActiveRecord.

A factory is very different from a keyword baked into the language. The new keyword suggests that the underlying language is doing the construction, and all of the details about the object being created are encoded in its blueprint, "Point."

I consider a factory and a keyword to be two very different patterns regardless of whether you want to call them class-based or prototype-based.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: