Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Prototype inheritance isn't actually very difficult for day to day use. Should all of these objects have a method attached to them? Okay, we'll add that to the prototype. Oh wait, you wanted `new Giraffe()` to be able to do all of the things that `new Mammal()` can do, plus some more? `Giraffe.prototype = new Mammal()`, done.

Oh, wait, you wanted to inherit from multiple places? That's a little harder; we'll need a for-in loop, but it's not too much code and it alerts you that you're probably Doing It Wrong. But wait, what will you do with the constructors? You don't have two `super()` functions or for that matter even one `super()` function. How do you call the last constructor? Oh yeah, that's right:

    function Mammal(s, n) {
        this.species = s;
        this.noise = n;
    }
    function Pet(n) {
        this.name = n;
    }
    function PetDog(name) {
        Mammal.call(this, "Canis lupus familiaris", "Woof.");
        Pet.call(this, name);
    }
... you `.call(this)` it to call it on this. And now both constructors are called where and how you need them, with no confusing "super()" function that you need to teach three times to people before they get it.

Compare this to Java where the moment that you want to merge two interface declarations you find yourself opening up a new file to do it.

I mean, Java has some nice points, but its idiosyncrasies make it pure pain when you're teaching CS 101. Here I was wanting to teach kids on day one about sorting strategies with a deck of cards, culminating in quicksort: "why don't we sort black from red first, then within black sort spaces from clubs first, then within spades sort high from low first...". That works and then I want to show them what it looks like in Code and I'm suddenly all like:

"Okay, this file is named Test.java and then there is a magic line `public class Test { public static void main(String[] args) {` which is a magic incantation to appease the Java demons living inside the `javac` program, and then we have to have a Card[] and that requires another file... oh f!ck it I'll just use integers, an int[]."

All of that stuff is idiosyncrasy which stops you from Getting Work Taught. It might help with Getting Work Done in large corporate dev teams, but it does not help with Getting Work Taught to small classes of confused individuals.



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

Search: