News for hackers. Stuff that matters.
Re:Instance Model Programming in C by skrebbel on Monday November 25, 2013 @03:37PM (#6796797)
Drifting from the topic, but I never understood this urgent need for so much inheritance when doing OO, especially when using languages that don't natively have it, like C and JavaScript.

I really like OO programming (i.e. I'm particularly not one of the functional-fundamentalist OO-haters here on HN), but as I've grown more experienced, I've started to use inheritance less and less, and composition more and more. This is trivially supported in C structs, and you don't need any fancy approach for it, plus you can do with way less void pointer casting, which means less runtime errors.

Inheritance is very useful for a small set of relatively complex problems, such as language parsing or UI frameworks or particle simulations. For many other problems, including most applications (as opposed to libraries), however, my experience is that you can do fine without. This holds especially these days, when many of said complex problems are solved in excellent freely available open source projects, in nearly any language.

Re:Instance Model Programming in C by Someone on Monday November 25, 2013 @05:15PM (#6797461)
That is far from an uncommon idea. The phrase to search for to learn more about this is "Composition over Inheritance". That leads you to e.g. http://en.wikipedia.org/wiki/Composition_over_inheritance or, combined with "site: c2.com" to http://c2.com/cgi/wiki?CompositionInsteadOfInheritance or http://c2.com/cgi/wiki?UseCompositionAndInterfacesWithoutCla....

In some sense, deep inheritance hierarchies were a thing of the 80's, when inheritance was new (at least, in the mainstream), just like the <blink> tag was a thing of the '90s (or was that the 00's?). Now, deep hierarchies are a code smell.

Re:Instance Model Programming in C by pjmlp on Tuesday November 26, 2013 @12:25AM (#6799324)
80's!?!

OO only started to get into the enterprise in the 90's.

Re:Instance Model Programming in C by 616c on Monday November 25, 2013 @03:47PM (#6796860)
That is funny because my limited experience with Python, on-off over the years, it was impressed upon me many, many times composition is superior to inheritance, and the language even has both built-in.

And yes, for all the pointy-hairs around, I know there are exceptions to the rule. I am speaking generally.

Re:Instance Model Programming in C by camus2 on Monday November 25, 2013 @05:19PM (#6797480)
Javascript supports prototypal inheritance natively and it works well. The problem is people trying to fit every java oo concept in js, ending up writing unreadable mess.
Re:Instance Model Programming in C by discreteevent on Monday November 25, 2013 @06:57PM (#6798031)
I agree and I think that this is what Go gets right. The thing that's valuable about objects are the interfaces (Alan Kay said it was the messages). Microsoft's COM is similar in this regard.