Re: How to use generics?
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 10 May 2007 10:43:00 -0700
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
.
- Follow-Ups:
- Re: How to use generics?
- From: Moty Michaely
- Re: How to use generics?
- References:
- How to use generics?
- From: Martin
- Re: How to use generics?
- From: Jon Skeet [C# MVP]
- Re: How to use generics?
- From: Mark Rae
- Re: How to use generics?
- From: Jon Skeet [C# MVP]
- Re: How to use generics?
- From: Mark Rae
- Re: How to use generics?
- From: Nicholas Paldino [.NET/C# MVP]
- Re: How to use generics?
- From: Chris Mullins [MVP]
- Re: How to use generics?
- From: Nicholas Paldino [.NET/C# MVP]
- Re: How to use generics?
- From: Chris Mullins [MVP]
- Re: How to use generics?
- From: Jon Skeet [C# MVP]
- Re: How to use generics?
- From: atlaste
- Re: How to use generics?
- From: Moty Michaely
- How to use generics?
- Prev by Date: Re: Is Partial Class feature required
- Next by Date: Re: Structure in CSharp
- Previous by thread: Re: How to use generics?
- Next by thread: Re: How to use generics?
- Index(es):
Relevant Pages
|