3 ms·
This is rather well studied subject - but this article does not add anything to the discussion. It talks a lot about names not much about their meaning. The on
by zby 16y ago
This is rather well studied subject - but this article does not add anything to the discussion. It talks a lot about names not much about their meaning. The only explanation he gives for the advantages or modules over classes is
<blockquote> In Ruby you don't declare your types, so you cannot get ambiguous instance variables: if you have two instance variables with the same name in different modules, then they're the same instance variable.
</blockquote>
as if this kind of unification of variables would obviously solve anything.
Despite linking to the Wikipedia, he also does provide the right definition of the diamond problem:
<blockquote>
This is the dreaded "diamond" problem that C++ programmers learn to fear: if your class has two superclasses that both define an instance variable named x, then you can have a hard time specifying which x you're using.
</blocquote>
Where is the diamond here?
- RodgerTheGreat 16y agoRegarding the diamond problem, I think he means that in the event of multiple inheritance, your class heirarchy would look like this: Object / \ A B \ / C Where A and B are parents of the class C. In most OO languages there will be an implied parent of A and B, like Object.
- kenjackson 16y ago"In Ruby you don't declare your types, so you cannot get ambiguous instance variables: if you have two instance variables with the same name in different modules, then they're the same instance variable." That line also bugged me. I struggle to see how that's a good thing. That seems like you could have code breaking in seemingly unrelated code due to seemingly common naming issues. That can't be right, can it?
- nusco 16y ago(From the original poster): You're right that I mischaracterized the diamond problem. I edited the post to fix that. My C++ mind model has been slipping away fast in part years. Definitely not like riding a bicycle.