J
Jon Skeet [C# MVP]
Peter Duniho said:Possibly. And yet a) most C# programmers, at least for the near future,
will in fact be C++ programmers migrating
I think I'd need to see some numbers before I believe that. I reckon VB
and Java programmers form a large proportion too - possibly larger than
C++ programmers.
and b) even if we reach a point
where most C# programmers are indeed ones who started out with C# and thus
have been indoctrinated in the languages subtle quirks, that does not in
my mind change the fact that having a "new" operator do two very different
things depending on the type of object on which it's operating is just not
a great idea.
Well, it does the same thing in some ways, and different things in
other ways. It does the "same thing" in the same way that both value
types and reference types are passed by value by default - if you
understand that the difference between reference types and value types,
it makes sense, although if you don't, it doesn't.
Note that, at least in my view, there *isn't* consistency of how you
create new instances of a type. When you use the "new" operator with a
struct, you aren't really creating a new instance of that type. The new
instance of a struct is created when the containing object is created
(whether that's on the stack, or in a class, or another struct). The
"new" operator doesn't really create the instance that you're using.
I think it depends on exactly what one means by "instance", to be
honest. I nearly used the word "value" but thought that wouldn't be
clear. It's quite possible that we don't have adequate terminology at
the moment.
(Just to be clear, I'm sure we agree on what actually happens, just not
on what we call it.)
So I'm not really on board with respect to your thought that over time,
we'll be left with "the benefit of consistency of how you create new
instances of a type". I don't see that consistency today, and so don't
see that we'll be left with that in the future.
I suspect we'll have to agree to disagree on this, but I'm fine with
that.
It's a classic example of inappropriate operator overloading, IMHO. It
falls in with other C#/.NET "features", such as the use of the word
"event" to describe something very different from a "WaitableEvent", as
well as the use of the method name "Invoke()" to describe one thing in the
Form class, and something somewhat different on a delegate.
Yes - I've just been writing about delegates and trying to write
coherently about Control.Invoke vs Delegate.Invoke. It's insanely
difficult to make it readable.
It's certainly not a big deal...any person spending any significant amount
of time with C# can easily get accustomed to these issues. But they do
detract from the general theme of C# and .NET of trying to avoid apparent
ambiguity.
Whereas I quite like not having to have two different types of syntax
for calling constructors.
Out of interest, what would you propose for calling a value type
constructor? (Please not the C++ syntax!)