Re: How to use generics?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Thu, 10 May 2007 02:01:37 -0700, Moty Michaely <Moty.Mi@xxxxxxxxx> wrote:

We can't avoid features just because developers don't know how to
develop.

Of course we can. Languages do it all the time. C# perhaps does it more than other languages, but each language always puts some limitation on what is allowed.

Would you drop Multi threading just because a developer can cause a
dead lock?

That depends on how useful multi-threading is. Given that so much of .NET is based on use of the thread pool and background worker threads, it would be folly to toss out multi-threading. It's integral to the design of ..NET. But multiple inheritance is not.

I can't really comment on *why* C# is missing multiple inheritence, not being privy to the decision-making that went into the design of C#. However, I think that the approach C# has taken is pretty sensible. You can still inherit multiple *interfaces*, which address all of the benefits anyone might claim for multiple inheritence, while preventing some of the basic "gotchas".

One of my biggest complaints with MI has been when I am trying to multiply inherit objects that ultimately inherit from some very basic class, like Object, that is intended to support fundamental object instance management. You can have a single object that provides multiple behaviors, but you don't have to worry about which of the multiply-inherited classes will be used for the basic object foundation, since there can be only one actual inherited class.

As far as the complaint about "manually implementing it in 10 different classes" goes, surely we all know how to use copy-and-paste here. It should not be necessary to literally write 10 implementations of a shared interface. You write the implementation once, contain an instance of that implementation in each class you want to provide the interface, and then wrap the implementation in stubs. Stubs that can be copied and pasted into each class inheriting the interface (and since the important stuff is actually just in one place, the usual big problem with copy & paste doesn't apply...bugs still get fixed in just one place).

Is that more tedious than just inheriting the interface? Sure, I don't disagree with that. But it really should not be a significant overhead.

And I definitely take issue with statements like "MI is like sight. If you grew up with it, you miss it dearly. If you never had it, you can not imagine what its like" and "if you write (proper) C++ for a couple of years, half the code you will write will contain MI". Those statements essentially dismiss prejudicially any argument not in favor of MI.

I have used multiple inheritance, I can imagine what it's like, and I am happy to not have it in C#. Likewise, I've been writing C++ for much longer than "a couple of years", and nowhere near "half the code" I write has MI. In fact, I stopped using it altogether when I get sick and tired of the headaches it caused (see above and Christof's post regarding base classes being inherited multiple ways). The implication in the latter quote above is that I haven't been writing "proper" C++ code; at best, the statement is tautological, and at worst it's insulting to me and anyone else who uses C++ without multiple inheritance.

Pete
.



Relevant Pages

  • Re: CLOS Properties Question
    ... I may find that the primary shortcoming of both of the ... >>languages I cited is lack of multiple inheritance, ... this syntactic sugar in C# is nifty...I don't ...
    (comp.lang.lisp)
  • Re: initializing mutable class attributes
    ... And yes, with multiple inheritance, you definitely have to know ... And Java simply solves the problem by not allowing ... It's interesting to compare languages like that. ...
    (comp.lang.python)
  • Re: Object-based inheritance in Python
    ... > By the way, if you are googling, you want probably look for 'prototype based ... > languages'. ... There are a few problems with current programming languages that only ... come to bite you at large scale projects (Multiple Inheritance, ...
    (comp.lang.python)
  • Re: "Must instantiate controlled types at library level." Why?
    ... You will have this for free with multiple inheritance. ... You cannot have objects of an abstract type (interface). ... Is it impossible to have a generic function that operates on ... we could create such supertypes as necessary *afterwards*. ...
    (comp.lang.ada)
  • Re: Multiple Inheritance
    ... Then, to me, it can be read "Multiple inheritance, as done in C++, ... was discarded from Java". ... that multiple interface inheritance is not multiple inheritance. ... showed that your quoting of "Gosling" (if he really did write ...
    (comp.lang.java.programmer)