How about spec terms? Spec 1.7 C#
"Like classes, structs are data structures that can contain data members and
function members..."
The preceding implies similarity does it not?
Similarity, yes. "Related by blood"? That's certainly not backed up by
the spec.
The fact that these are both
data structures shows some close family relation.
Not particularly - partly because "family relation" isn't a well-
defined term in computer science. That's why I asked what you really
meant by it.
In fact, spec 11.3 goes so far as to delineate the difference between
structs and classes. Why? Because they are so similar that one may be
confused for the other hence the reason for the literature. (That is my
interpretation of spec 11.3)
They're certainly similar enough to warrant a comparison. They're not
similar enough to talk about one as being a lightweight or heavyweight
version of the other.
I sincerely do not believe that anyone in here thinks that a struct is a
class or a type of class for that matter. I believe it to be a manner of
speaking only. I cannot argue against the technical merit for requiring a
clear distinction in terminology. However, my position is that it is not
sufficiently disturbing to warrant such drastic changes to the literature.
What literature? I'm talking about people casually referring to structs
as "lightweight classes" as if this passed on any worthwhile
information. Instead, it leaves a misleading impression.
Since the majority of programmers who have a real need for structs do so
because they have a driving need. That need can only be filled firstly if
the programmer has a deep understanding of the difference.
Absolutely - and calling structs lightweight classes does *not* give
that deep understanding or even hint that deeper understanding is
required. People make decisions based solely on the fact that structs
have been described as lightweight classes. They shouldn't, but they
do. That's human nature.
I also fail to see the argument framed to include C++ programmer confusion.
After all, destructor syntax is horribly confusing to C++ programmers. But
we did survive this bout and Jon did not complain about the destructor
syntax either. So why now? We need to focus instead on structs and classes
inside C#. Those migrating to C# need to use an appropriate resource and be
guided accordingly while understanding that material presented in the
newsgroup is not guaranteed accurate and should be taken with a good dose of
salt and a pinch of asprin.
So you're saying that describing a struct as a lightweight class isn't
accurate, but that's okay because no-one should trust what's said on a
newsgroup anyway? Okay then - maybe I should start calling structs
"heavyweight classes" then. After all, it can't do any harm, can it?
That is a horrible analogy.
I don't think so. In all cases:
a) The "simplified" version tells a tiny part of the story
b) The tiny part of the story which is told distracts from the bigger
picture
c) People have been confused by the "simplified" version
And for that matter, both sides have presented
horrible analogies that were self-serving. These analogies are without merit
because they were all carefully constructed to eluminate one side of the
argument - this one in particular is equally guilty.
Can you refute any of the above points?
Because it is tedious. It's the long way around the track when a shorter,
simpler explanation can work just as well for the majority of the 10 million
programmers out there.
Except it doesn't. We've seen people be confused by calling structs
lightweight classes. Do you really want to contribute to confusion? I'm
not suggesting that you write a huge long explanation every time. I'm
suggesting that you find a resource which explains it properly, and
reference that instead.
I'd agree here with you but I believe that the struct vs class argument is
unique and should benefit from certain semantic liberties.
I don't believe it's unique, but I believe it's so important that it
absolutely *can't* benefit from semantic liberties. It's not that
complicated - it *gets* complicated when people take semantic liberties
so that when someone wants to find out the truth, they've got to
"unlearn" the myths they've heard first.
Most people understand classes but few understand structs well.
And the fact that people keep referring to structs as "lightweight
classes" is one of the contributing factors to that lack of
understanding.
There is merit in explaining one in terms of the other.
I've never disputed that.
Notice this is the approach the specification takes and then proceeds
to differentiate the two. There's nothing wrong with that. Or would
you prefer to rewrite the specs?
You seem to have created a straw man argument, as though I've been
arguing against comparing structs and classes. I never have. I've just
said that calling structs lightweight classes and leaving it at that
creates a misleading impression, and that's a bad thing to do. The
specs *don't* do that, of course - they give details, which is what
I've been arguing for the whole time.