Am Mon, 14 May 2007 19:59:56 +0100 schrieb Jon Skeet [C# MVP]:
I agree, although they work okay for implementing interfaces, provided
you don't mind the cost of boxing.
No sire, they do not. Boxing transfers the value object into something
completely different. THERE IS NO SUCH THING AS virtuality / polymorphism
etc. for value types.
I agree that you can create a reference type from a value type, and that
language designers might come to the conclusion that such conversion should
sometimes be implicit. The result of such conversion is NOT of VALUE TYPE!
<snip parameter passing example>
I agree, you need to know whether you're dealing with a value type or a
reference type. Mutable value types are bad idea in general though, and
should be avoided, making this kind of thing less of an issue.
No, I strongly disagree. Two reasons:
1.) If you have for example a Rect structure .... how can you e.g. increase
it by 1 pixel without changing the values?
2.) Original problem still remains. What do we know of the passed object
after f has executed:
void f( V v )
{
v.g();
}
if
- V is of value type?
- V is of ref type?
Seems to be the same problem to me.
But it wouldn't meet mine, probably due to different backgrounds.
No, but I suspect I'm not the only one who will expect there to be an
implicit conversion from any type to its base type.
I don't understand. You think in terms of reference-semantics. For value
types, there are no references.
I hope, after the statements
int i = 5;
int k = i;
k = 0;
you do not expect i to have the value 0......
These statements transfer values! Then it is absolutely logical that the
statement in
D d = ....
B b = d;
creates a completely new B-object and initializes it with *the values* from
d.
For value types, I do not expect that b now "points" to a D-object.
True, but I think you'll agree it makes derivation less useful if you
don't get polymorphism, I think which makes it a reasonable argument
against inclusion - it means the added language/framework complexity
doesn't have as much payback as might be expected on first glance.
Also here, I don't see this. Complexity cannot be the issue. If we say,
that we can derive at all, derivation for value types is not too complex to
comprehend at all. For beginners, the distinction between value types and
reference types is much more difficult, especially because there is no
notational difference.
Greetz
Paule