Go's unique approach to OO
drdobbs.com
drdobbs.com
for _, painter := range []Painter{label, listBox, button1, button2} {
painter.Paint()
}
In C++, where inheritance is used, the virtual function pointer tables are maintained and the inherited class will have the function at the same index which makes calls of virtual functions slower than normal calls but the cost is still just an indexing of the table. However when there is no inheritance specification, the indexes can't be maintained, I presume. The easy solution is that calls are resolved using some string fingerprint lookup but that would make such calls really slow (compared to the C++).Then how do they do it?
Given that, it seems easy enough to just pass a {pointer, vtable} value.
In C++ (if I understand correctly) each object/class has one vtable. In Go, it seems that each type has as many vtables as are needed for the contexts it's called in.
See also type classes in haskell.
(this is all guessing. Someone please call me out if I'm wrong)
[1] www.research.ibm.com/people/d/dgrove/papers/oopsla01.pdfThe more general ideas that underpin a composition implementation are the abilities to access class/interface metadata at compile time and to generate code programmatically at compile time.
Every project has friction between members, disagreements,
conflicts over style and philosophy. These social problems
are counter-acted by the fact that no large project can be
accomplished otherwise. "We must all hang together, or we will
all hang separately." But the expressiveness of Lisp makes
this countervailing force much weaker; one can always start
one's own project. Thus, individual hackers decide that the
trouble isn't worth it. So they either quit the project, or
don't join the project to begin with. This is the Lisp Curse.Maybe not a good tutorial for people new to Go.