I wouldn't even say that though. If you have two types which each have
20 instance fields (all ints for the sake of argument). The only
difference between them is that one is a class and one is a struct. You
need to use these types as parameters and return values frequently. Now
which feels like a heavyweight type and which feels lighter?
Practical experience with a given struct has no bearing on what I
said. Structs exist for the purpose of being more lightweight than
classes, and that purpose is reflected in their implementation.
Where exactly is "lightweight class" defined in the first place? It's
not in the C# spec as far as I'm aware - the C# spec gives details
instead of relying on inappropriately brief descriptions.
First, a literal reference from an authoritative source:
MSDN Library, "C# Programming Guide":
"A struct can be considered a lightweight class, ideal for creating
data types that store small amounts of data, and does not represent a
type that might later be extended via inheritance."
http://msdn2.microsoft.com/en-us/library/ms173109.aspx
Interestingly, C++/CLI uses the keywords "value class" as opposed to
"ref class" = reference type. Here's a paper on the subject by Rex
Jaeschke, standards editor for C++/CLI, CLI, and C#:
Rex Jaeschke, "A lightweight class mechanism", Dr. Dobb's Journal:
"The value class is a lightweight C++/CLI class mechanism that is
particularly useful for reasonably small data structures that have
value semantics."
http://www.ddj.com/dept/cpp/184401955
And here are a number of references that call structs "lightweight"
although they avoid the term "class" since it's already used as a
synonym for "reference type" in the context of the explanation:
MSDN Library, "C# Programmer's Reference":
"The struct type is suitable for representing lightweight objects such
as Point, Rectangle, and Color. Although it is possible to represent a
point as a class, a struct is more efficient in some scenarios."
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcrefStructTypes.asp
Jeff Richter, "CLR via C#", Microsoft Press, page 124:
"To improve performance for siple, frequently used types, the CLR
offers light-weight types called value types."
Steven Holzner, "Object-Oriented Programming in C#", Sams:
"Structs in C# are like lightweight versions of classes. [...] They
take up fewer resources in memory, so when you've got a small,
frequently used class, give some thought to using a struct instead."
http://www.samspublishing.com/articles/article.asp?p=101373&seqNum=9&rl=1
Fahad Gilani, MSDN Magazine, "C# in Depth" series:
"For scientific applications, value types can be fast, efficient, and
an excellent choice over reference types whenever possible. In the
next section, I'll take a look at one of the many uses of user-defined
lightweight data types in scientific programming."
http://msdn.microsoft.com/msdnmag/issues/04/03/ScientificC/
Other sources do not use the literal term "lightweight" but still
highlight the cheapness and efficiency of value types as compared to
reference types when introducing the concept:
Eric Gunnerson & Nick Wienholt, "A Programmer's Introduction to C#",
Apress, page 79:
"Sometimes, however, it may be desirable to crate an object that
behaves like one of the built-in types -- one that's cheap and fast to
allocate and doesn't have the overhead of references."
Don Box with Chris Sells, "Essential .NET vol. 1", Addison-Wesley,
p.133:
"In particular, instances of value types do not carry the storage
overhead of full-blown objects. This makes value types useful in
scenarios where the costs of an object would otherwise be
prohibitive."
So I hope we can agree that structs are, in fact, commonly introduced
as lightweight types in the literature. The motivation is in fact to
have a type that is less expensive than a reference type.
I don't think it's particularly helpful to use terminology which you
*know* causes confusion on the grounds that people should learn more
about the subject so as to avoid being confused. We get the situation
where there are two types of reader: those who don't already know what
a struct is (who will be confused by your description) and those who do
(who won't gain anything by your description). Where exactly is the
benefit?
Like the cited authors, I don't share your opinion that readers who
don't already know about structs will invariably be confused about the
"lightweight" moniker. Again, I think it's accurate and helpful.
When I was learning C# I found this characterisation appropriate and
useful in forming a mental concept of the purpose and implementation
of structs. The copy-on-pass semantics are always highlighted in the
vicinity of such an introduction, so I never had a problem with that.
Frankly, I don't see why we should give any regard to people who run
off and implement something (badly) after seeing a single adjective-
noun pair, as if that would explain everything! Of course it doesn't,
but what kind of programmer would assume that it does?