

Think in Go: Go's alternative to the multiple-inheritance mindset. - peregrine
https://groups.google.com/forum/#!msg/golang-nuts/Rj5t1h_ztxI/Fgs6HfLqMHAJ

======
ggchappell
This is an interesting discussion -- interesting in part because it addresses
a mindset that I don't seem to have.

C++, for example, has multiple inheritance, and I have used it to good effect.
OTOH, if I needed to implement Dijkstra's Alg in C++, then I don't think it
would even occur to me to inherit from both a priority queue and a directed
graph base class. (And even now that it does occur to me, it doesn't seem to
be a good idea.) Rather, I'd use something akin to the interfaces presented
here. Of course, interfaces are not formalized in C++, but the C++ culture
does include the notion of a _concept_ , to be used with a template.

If the language were Python, I'd proceed similarly. And then there's Java,
which doesn't even have multiple inheritance. I've never heard anyone claim
that Java is somehow ill-suited for the implementation of graph algorithms
(but maybe it is -- never thought about it).

Perhaps what this discussion is overturning, is not so much a _multiple-
inheritance_ mindset, as an _Eiffel_ mindset. (But I don't know much Eiffel,
so it's hard to say.) And the discussion also suggests that Go's formalization
of interfaces can be a Good Thing.

~~~
_delirium
I also don't know much Eiffel, but I believe this 1988 article is the
canonical pro-multiple-inheritance-in-Eiffel piece (by Eiffel's creator):
[http://archive.eiffel.com/doc/manuals/technology/bmarticles/...](http://archive.eiffel.com/doc/manuals/technology/bmarticles/joop/multiple.html)

------
delinka
Slightly off-topic: the web in general seems broken for mobile. To get this
content on my iPhone, I had to concoct this URL:

[https://groups.google.com/forum/?nomobile=true#!msg/golang-n...](https://groups.google.com/forum/?nomobile=true#!msg/golang-
nuts/Rj5t1h_ztxI/Fgs6HfLqMHAJ)

Then, I discovered that to see more content, I had to swipe up with two
fingers. There were no scroll indicators. This and the scaling problem ("you
cannot rescale this web site. We have decided for you that this size is
perfect. And no scrolling to see the words that run off the edge of the
screen.") are...well, problems.

~~~
p9idf
As with all of their other products, Google is in the process of breaking the
Groups UI by adding useless frames and whitespace. Try this instead:

[http://groups.google.com/group/golang-
nuts/msg/7030eaf21d3a0...](http://groups.google.com/group/golang-
nuts/msg/7030eaf21d3a0b16)

------
zanst
Russ, Ken, Rob and the other guys are making a great work in Go. It's weird
that people are not yet paying much attention to it - and to Plan 9 as well.

------
supersillyus
Does what he's describing as the Go Way basically equate to generic
programming in general, or is there something specific to Go about it?

~~~
Rusky
It's sort of Go-specific, but the same style is also used in Haskell using
typeclasses, Scala/Ruby/etc using mixins/traits, and C++ using templates.

Rather than inheriting from some base class, you just make sure your class can
do certain operations and then other stuff works on that- it's good way to
decouple algorithms, containers, etc. from the types they work with.

~~~
caffeine2
The comments in his code are reminiscent of programming by contract (an idea I
believe Djikstra himself was fond of). In Go the types of the interfaces are
statically checked, which is good (in Python or Ruby, this isn't the case),
but the contract the interface represents has to remain in comments and unit
tests.

It would be nice to be able to specify tests that every implementor of the
Heap interface must pass?

~~~
burgerbrain
I am a fan of programming by contract myself, but I'm not quite sure it could
be pasted onto Go's interfaces quite so simply. In the case of Heap perhaps it
could be done in a straight forward way, but what about more generic things
that have more to do with side-effects?

------
pointyhat
This requires me to sign in to a Google account (I don't have one). Bring back
usenet!

~~~
dchest
<http://pastebin.com/iPibD66C>

~~~
pointyhat
Thank you - much appreciated :)

