Is Class Synonymous with Type?

M

Mark Wilden

Jon Skeet said:
No, but then I'm not the target audience, as I already understand the
type system. We'd have to ask the OP whether it helped or not - and
even the OP may not know, as he may think he understands when he
doesn't, or vice versa.

You know, I see a lot remarks like this that assume the real problem with a
concept or explanation is not that it's confusing to the speaker, or even to
anyone else in the conversation, but that it's bad because it just might
confuse some hypothetical idiot. This same line of thinking is used to
deprecate features like multiple inheritance. It's not that -we- would have
any problem using it - no, sir - but we feel for the poor newbies who will
screw it up.
It wasn't implied - it was stated:

<quote>
In a nutshell a general interface is a particular set of signatures.
</quote>

You're right - my mistake.
Now that would be fine in itself, but then when someone starts learning
about C# interfaces, how do they talk about the difference between
classes and interfaces, if they've learned about classes in terms of
interfaces meaning something different?

I think the term "interface" has a much broader meaning that every
programmer must understand.
Overloading terms just seems like a bad idea to me.

It may be bad in one instance or another, but it can't be bad in general,
since our whole language is based on it.
but when there are alternatives, I think it's a good idea to use them.

The thing is that, unless you're an Eiffel programmer, you'll generally hear
"interface" (the non-C# usage, which is many years older than the C# usage)
defined in terms of "contract." "Contract" is way more overloaded than
"interface"!
For example, suppose Jeff had used the word "contract" instead of
"interface" when talking about "general interfaces". He could have
specified what he meant by "contract" just as easily as he did "general
interface" and it wouldn't have interfered with the C# meaning of the
word "interface" at all.

However, I admit that I don't think that would be a bad idea.
I don't think we can know that.

Yes, we can know whether or not there -seems- to have been confusion. There
doesn't. That doesn't mean none exists, but there's no evidence that it
does.
 
D

Dustin Campbell

Gary,

I'm recommending an excellent book out there by Jeffrey Richter call "CLR
via C#". You're certainly welcome to ask questions here (especially since
some of them have spawned enjoyable debate) but you will probably find the
explanations in this book to be fantastically clear. There are entire chapters
devoted to what .NET types are.

http://www.amazon.com/CLR-via-Secon..._bbs_sr_1/104-0992090-2716705?ie=UTF8&s=books

Best Regards,
Dustin Campbell
Developer Express Inc.
 
M

Mark Wilden

Dustin Campbell said:
Which is why (as Jon has pointed out) it's dangerous terminology and other
words should probably be chosen. In this newsgroup, we *are* in the
context of an audience after all. Therefore, it's a confusing definition
to post.

Were you confused?

///ark
 
D

Dave Sexton

Hi Mark,

"is" is the 3rd person present singular of "be". This is true even in C# :)

http://dictionary.reference.com/browse/is

Anyway, even if there was any ambiguity in "is" it wouldn't really prove
your original argument at all. The fact remains that "contract", as Jon
pointed out, is not an overloaded term in C#, and is therefore more
appropriate. "Interface" and "generic" are overloaded terms and are
therefore less appropriate.

As far as your education is concerned, this thread might as well not exist
since you probably already understand the topic. For those that find the
information to be valuable and may actually learn something, it's better to
be accurate and clear.
 
J

Jon Skeet [C# MVP]

This thread has been more help than any can imagine. I really am
indebted to all of you for sharing your insights into this.

As a (very useful) excercise I have spent the last couple of hours
reading over the thread trying to get a grasp on the different aspects
that have been raised. In summary am I correct to say the following: -

A Class is a mechanism for creating a new type.

Well, it's more that a class *is* a type.
Native types are defined by the clr, and for that reason do not require
the programmer to define them by creating new classes. All native types
are classes. All of them, be they reference or value type are derived
from the ultimate base class Object.

I dispute Kevin's claim about all managed types being classes, so I'm
afraid there'll be some disagreement there.

Also note that System.String is a type which is defined in the CLI spec
(IIRC).

The question of inheritance and value types is a slightly tricky one,
and I seem to remember that the C# spec and the CLI spec approach the
matter using different terminology. (In particular, I'm pretty sure
that the CLI spec treats "derives from" and "inherits from" as subtly
different concepts, even though the two are used interchangably in most
conversations.)
The different user defined types available in C# are:
Class, Interface, Struct,Enum,Delegate.

I don't think it's worth making the "user-defined" distinction there.
When a variable is Instantiated it becomes a bit of memory.

The variable doesn't "become" a bit of memory. A variable has a name
and a value. Depending on the variable, it may be
This bit of memory either stores a label (for value types)
or a pointer (which is a memory address) for reference types.

Not sure what you mean by "label" here.
Questions: -

Q.1.
Kevin made the distinction that All MANAGED types are classes.
What does managed/unmanaged mean in this respect?
and does this mean that UNMANAGED types are not classes. What is an
example of an unmanaged type? What implications does such a type not
being a class, have?

As I said before, I disagree with Kevin in terms of whether value types
are classes or not, so I'm not sure I can really speak to this one.
Q.2.
When I look at a class from now on I will look at it as ultimately
defining a user type, is this correct?

Depends what you mean by "user type" and "look at". There are plenty of
classes defined by the framework and not by "users" as such.
Q.3.
In order for a class to 'define' a type, it must say something about
this type, what does a class say about the type that it defines, and
how does it say it?

It describes any or all of:
methods, variables, events, properties, constructors,
static constructor, finalizer, nested types

(There's probably something else I've missed off, but that's basically
it.)
Q.4.
All classes are types. I do not understand this.

Any class is a type, as is any struct.
A type of variable indicates the data the variable can store, and the
operations that can be performed on that variable.
Yes.

But if i create a class which simply has an empty main method, how can
this be called a type? in what way is it defining data, or operations
that can be performed on data?

If the class just has a static Main method, you could still call
ToString, GetHashCode etc on it, even though they wouldn't give you any
useful information. It wouldn't be defining any extra data or
operations which could be called on instances of the type - but almost
all classes do.
I hope my naivity on this matter isn't too annoying for you. This seems
so easy to most of you, it must be quite painful to witness my lack of
grasp of these points!

It's not painful, but I still think that books are a better way of
getting a handle on this kind of topic.
 
J

Jon Skeet [C# MVP]

Mark Wilden said:
You know, I see a lot remarks like this that assume the real problem with a
concept or explanation is not that it's confusing to the speaker, or even to
anyone else in the conversation, but that it's bad because it just might
confuse some hypothetical idiot. This same line of thinking is used to
deprecate features like multiple inheritance. It's not that -we- would have
any problem using it - no, sir - but we feel for the poor newbies who will
screw it up.

I have no problem in saying that I'd probably screw up using multiple
inheritance :)

I fail to see what's controversial about the idea that a statement that
is understandable to those who already know the subject matter could be
confusing to those who are new to the topic though.

As an example, if I were to use the word "reference" in two different
ways in the same sentence (talking about "pass by reference" semantics
and "reference types") I would expect people who understood parameter
passing and the type system to understand what I meant, but I *know*
this causes confusion for a lot of people.

I think the term "interface" has a much broader meaning that every
programmer must understand.

Yes, but in the discussion of C# types it's almost always used to mean
the C# interface, and overloading it there seems like a bad idea to me.
It may be bad in one instance or another, but it can't be bad in general,
since our whole language is based on it.

It causes confusion when multiple meanings are available within the
same context, both in computing and in "normal" conversations. Heck, if
that weren't the case, a lot of sit-coms would far fewer jokes!
The thing is that, unless you're an Eiffel programmer, you'll generally hear
"interface" (the non-C# usage, which is many years older than the C# usage)
defined in terms of "contract." "Contract" is way more overloaded than
"interface"!

But not within the context of the C# type system, as C# doesn't define
the term "contract" anywhere. That's the important point, IMO.
However, I admit that I don't think that would be a bad idea.


Yes, we can know whether or not there -seems- to have been confusion. There
doesn't. That doesn't mean none exists, but there's no evidence that it
does.

I can't see there's any evidence either way. It's like me saying that
you don't seem to have any knowledge of music - I have no evidence
either way, so you *could* argue that it's a valid statement. It paints
a different picture to the reality, however, which is just that I don't
have any clue about how much you know about music.
 
D

Dustin Campbell

I dispute Kevin's claim about all managed types being classes, so I'm
afraid there'll be some disagreement there.

As much as I disputed with him I have to agree that he is correct from the
standpoint of the CLR and the .NET framework. At the metadata-level, everything
really is a class. Believe me, I spend a great deal of time dealing with
the bits in the metadata tables themselves. However, the C# notion of a class
is really akin to CLR reference types. So, his assertions, while true, weren't
really appropriate to this thread. They just added confusion where none further
was needed. :)

Best Regards,
Dustin Campbell
Developer Express Inc.
 
J

Jon Skeet [C# MVP]

Dustin Campbell said:
As much as I disputed with him I have to agree that he is correct from the
standpoint of the CLR and the .NET framework. At the metadata-level, everything
really is a class. Believe me, I spend a great deal of time dealing with
the bits in the metadata tables themselves. However, the C# notion of a class
is really akin to CLR reference types. So, his assertions, while true, weren't
really appropriate to this thread. They just added confusion where none further
was needed. :)

Hmm... did you see my other post responding to Kevin's? Perhaps it's
just that the CLI spec is tragically poorly written in this respect,
but I see very little way of interpreting statements such as:

<quote>
Simplicity: in particular, variance is only permitted on generic
interfaces and generic delegates (not classes or value-types)
</quote>

other than to consider value types not to be classes. (It also suggests
that generic interfaces and generic delegates aren't classes, which
contradicts Kevin's statement unless you view generic
interfaces/delegates as not being types.)

I have a vague recollection of you posting some convincing evidence on
this front before, but couldn't find it recently - do you have any
quotes from the spec which would help?

My guess is that the spec is just contradictory, unfortunately.

I can see that a value type is declared using .class in IL, but that's
not quite the same thing as the concept of a class.

Indeed, looking at partition II's section 10, "Defining types" it
starts with:

<quote>
Types (i.e., classes, value types, and interfaces) can be defined at
the top-level of a module
</quote>

Again, doesn't that sound odd if value types and interfaces *are*
classes? Can you imagine the furore which would occur if someone
described a city has containing: "People (humans, women, and
Christians)"?


For further evidence, look at Partition II's table of contents which
contains sections: "Semantics of classes", "Semantics of interfaces",
"Semantics of value types" and "Semantics of special types". That,
again, suggests that value types aren't classes.

Similarly, in 13.3:
<quote>
Like classes, value types can have both instance constructors (§10.5.1)
and type initializers (§10.5.3). Unlike classes, whose fields are
automatically initialized to null, the following rules constitute the
only guarantee about the initilization of (unboxed) value types:
</quote>

If a value type *is* a class, how can "Unlike classes..." make sense?


My suspicion is that ".class" was a badly chosen name, but that it
*doesn't* always define a class.
 
M

Mark Wilden

Jon Skeet said:
I have no problem in saying that I'd probably screw up using multiple
inheritance :)

I've used MI a buncha times. It's really not a big deal. I had problems with
it when I first used it. I also had problems understanding pointers.
I fail to see what's controversial about the idea that a statement that
is understandable to those who already know the subject matter could be
confusing to those who are new to the topic though.

Oh, I completely grant that any statement could be confusing to anyone. But
"could be" is different from "is."
As an example, if I were to use the word "reference" in two different
ways in the same sentence (talking about "pass by reference" semantics
and "reference types") I would expect people who understood parameter
passing and the type system to understand what I meant, but I *know*
this causes confusion for a lot of people.

I'd have to see an example.
Yes, but in the discussion of C# types it's almost always used to mean
the C# interface, and overloading it there seems like a bad idea to me.

I know it seems like a bad idea to you. I just don't know if anyone actually
has trouble understanding it. You understood it. Dustin understood it. I
understood it. No one that we know of doesn't understand it. So there's
actually no evidence that the definiton is hard to understand.

That said, it doesn't hurt to be absolutely clear. I was really just talking
to my "hypothetical idiot" point (which is admittedly a pet peeve of mine).
I can't see there's any evidence either way. It's like me saying that
you don't seem to have any knowledge of music - I have no evidence
either way, so you *could* argue that it's a valid statement.

I do argue that that's a valid statement. It's completely, 100% true.

The example isn't pertinent here, though, since this newsgroup is about C#
(and explanations thereof), not music, and one's knowledge of C# is quite in
evidence here.

I do have evidence for my belief about the definition:

1) Based on my knowledge of and experience with programmers, I don't think
the definition would be confusing to most or even some of them.

2) No one has expressed confusion.

Hence, 3) It seems that the definition is not confusing.

Do I -know- that invisible pink hippos don't orbit Saturn? It just seems
pretty likely that they do not, based on reasoning enumerated above. Pace
Donald Rumsfeld, the absence of evidence -is- evidence (though not proof) of
absence.

///ark
 
D

Dustin Campbell

Jon,

I'm going to change my tune now and wisely stop arguing falsehoods. Truthfully,
when I see the phrase "all .NET types are classes", my gut instinct is to
go along with this. However, it really isn't true. The CLI has the notion
of a TypeDef and that is *not* synonymous with a class. A TypeDef can be
a Class, Interface or ValueType but not any combination of the three.

- A TypeDef is a "Class" when its Interface bit (0x00000020) of its TypeAttributes
flags is not set. And, it must ultimately derive from System.Object.
- A TypeDef is an "Interface" when its Interface bit is set. It doesn't inherit
from anything.
- A TypeDef is a "ValueType" when its Interface bit is not set and it ultimately
derives from System.Object.

In addition to TypeDefs there are TypeSpecs which describe other kinds of
types (e.g. pointers, arrays, closed generic types, etc.). Often, these reference
TypeDefs.

And finally, there are TypeRefs which are simply references to TypeDefs or
TypeSpecs that appear in other modules.

The CLI spec seems ties the notion of a "class" to a "reference type".

Best Regards,
Dustin Campbell
Developer Express Inc.
 
D

Dustin Campbell

As an example, if I were to use the word "reference" in two different
I'd have to see an example.

Mark, I don't want to assume that you don't teach programming to other developers
but, as a trainer, I see this sort of confusion all the time. Developers
come from lots of different backgrounds at many different levels. And, it's
likely that a large percentage of this newsgroup's audience are C# learners
-- not experience C# developers. So, using the least confusing language as
possible is always a good idea here (though that's not always achieved by
yours truly).

Best Regards,
Dustin Campbell
Developer Express Inc.
 
D

Dave Sexton

Hi Mark,

I do argue that that's a valid statement. It's completely, 100% true.

The example isn't pertinent here, though, since this newsgroup is about C#
(and explanations thereof), not music, and one's knowledge of C# is quite
in evidence here.

I do have evidence for my belief about the definition:

1) Based on my knowledge of and experience with programmers, I don't think
the definition would be confusing to most or even some of them.

2) No one has expressed confusion.

Hence, 3) It seems that the definition is not confusing.

Do I -know- that invisible pink hippos don't orbit Saturn? It just seems
pretty likely that they do not, based on reasoning enumerated above. Pace
Donald Rumsfeld, the absence of evidence -is- evidence (though not proof)
of absence.

There is no evidence of anybody's particular level of experience or
knowledge other than the very few people posting, and any assumptions you
make thereof is a priori, not empirical. I'm sure there are many more
people from all over the world reading this thread, with experience varying
in great degree, other than just the few that are participating in this
conversation. Everybody's needs should be catered to here seeing that it's
a public newsgroup, and that can't be done accurately and clearly using
loose terminology.

I hope that's clear enough :)
 
M

Mark Wilden

Mark, I don't want to assume that you don't teach programming to other
developers

That would not only be a valid assumption - it would be a true assumption as
well. :)
but, as a trainer, I see this sort of confusion all the time.

The difficulty is in qualifying "sort of."
So, using the least confusing language as possible is always a good idea
here (though that's not always achieved by yours truly).

It's impossible to use the least confusing language possible. If it were,
every post would be terabytes long. At some point, you have to be able to
assume a certain background. And understanding how "interface" in general
and "interface" as a C# construct are not identical would, I feel, be part
of most programmers' backgrounds. Maybe not. But I'm sticking with it.

Anyway, we're both arguing based on the characteristics of people we don't
even know - the readers of one particular newsgroup message. Which is kinda
silly, but which characterizes a lot of the arguments I participate in. :)

///ark
 
M

Mark Wilden

There is no evidence of anybody's particular level of experience or
knowledge other than the very few people posting

Exactly. There is no actual evidence that anyone was confused by the post.
Hence, any assumption that the post was confusing is a priori, not
empirical.
, and any assumptions you make thereof is a priori, not empirical.

D'oh! :)
Everybody's needs should be catered to here seeing that it's a public
newsgroup

It is impossible to cater to everyone's needs.
and that can't be done accurately and clearly using loose terminology.

What we're arguing about is the definition of "loose." A type theorist might
say that any definition that uses words instead of mathematical symbols is
"loose."

///ark
 
J

Jon Skeet [C# MVP]

Dustin Campbell said:
I'm going to change my tune now and wisely stop arguing falsehoods. Truthfully,
when I see the phrase "all .NET types are classes", my gut instinct is to
go along with this. However, it really isn't true. The CLI has the notion
of a TypeDef and that is *not* synonymous with a class. A TypeDef can be
a Class, Interface or ValueType but not any combination of the three.

<snip>

Cool. I can stop trying to work out where the spec contradicts itself
in that case :)
 
J

Jon Skeet [C# MVP]

Mark Wilden said:
I've used MI a buncha times. It's really not a big deal. I had problems with
it when I first used it. I also had problems understanding pointers.

Unfortunately I'm finding it hard to
Oh, I completely grant that any statement could be confusing to anyone. But
"could be" is different from "is."

Good job I originally talked about it being "potentially confusing" and
it being "likely to lead to confusion" then :)
I'd have to see an example.

"When a reference type value is passed by value, it is the reference
which is passed, not the object; it is still passed by value (by
default) rather than by reference, but you need to be clear that the
value in question is a reference."

I often find myself making statements *like* that (hopefully a bit
clearer) because people associate "reference type" and "pass by
reference" when they shouldn't - and I believe that's largely *because*
the word "reference" appears in both.
I know it seems like a bad idea to you. I just don't know if anyone actually
has trouble understanding it. You understood it. Dustin understood it. I
understood it. No one that we know of doesn't understand it. So there's
actually no evidence that the definiton is hard to understand.

No, but I think it's
That said, it doesn't hurt to be absolutely clear. I was really just talking
to my "hypothetical idiot" point (which is admittedly a pet peeve of mine).

I think the difference is that I'm considering a hypothetical newbie,
not a hypothetical idiot. Were you an idiot when you didn't understand
pointers? No - just new to the idea.

In this case, we don't even need to look for a hypothetical newbie -
the post was a response to a *real* newbie (garyusenet) who has never
hidden his "newbieness". What we *don't* know is whether he found it
confusing, or whether he would have found it confusing if there hadn't
been all the other posts talking about types, or whether it may have
laid the foundations for confusion when he learns about interfaces.
I do argue that that's a valid statement. It's completely, 100% true.

The example isn't pertinent here, though, since this newsgroup is about C#
(and explanations thereof), not music, and one's knowledge of C# is quite in
evidence here.

And in this case, the OP's "newbieness" is in evidence too.
I do have evidence for my belief about the definition:

1) Based on my knowledge of and experience with programmers, I don't think
the definition would be confusing to most or even some of them.

Programmers with how much experience though? Having had to try various
ways of explaining certain concepts in the past, I believe a C# newbie
could very easily be confused by the different uses of "interface" in
the statement, either when they first hear it or later when they then
start to use C# interfaces.
2) No one has expressed confusion.

Hence, 3) It seems that the definition is not confusing.

I disagree with the logic there, because it's so easy for it to have
confused someone a) without them knowing or b) without them wanting to
display that ignorance.
Do I -know- that invisible pink hippos don't orbit Saturn? It just seems
pretty likely that they do not, based on reasoning enumerated above.

Given that I disagree with you on point 1, it's unsurprising that I
disagree with the conclusion.
Pace Donald Rumsfeld, the absence of evidence -is- evidence (though not proof) of
absence.

It's evidence, but not particularly strong evidence - whereas I believe
that the evidence of common sense is that overloading terms
unnecessarily (within a context where there is a specified meaning of
those terms) leads to an unnecessarily high potential for confusion. In
this case, I think the potential is great, and you disagree, which is
fine.

I've seen enough people getting confused by relatively clear
descriptions of the type system to want to err on the side of caution.
 
D

Dave Sexton

Hi Mark,
Exactly. There is no actual evidence that anyone was confused by the post.
Hence, any assumption that the post was confusing is a priori, not
empirical.

But you've only addressed half of my point. There is also no evidence that
it helped anyone, so you have no base for your claim.

I was suggesting that we can't know either way, with any degree of
certainty, unless we were to take a poll or something. Therefore, it's best
to be as clear as possible when posting since you never really no who will
be reading it.

As for any OP's level of expertise, what you assume as a respondent may set
the basis for the amount of detail in your reply, but any assumptions made
thereof should by no means allow a reduction in clarity in any form.
D'oh! :)
;)


It is impossible to cater to everyone's needs.

It's not impossible to try.
What we're arguing about is the definition of "loose." A type theorist
might say that any definition that uses words instead of mathematical
symbols is "loose."

Our [discussion] isn't focused on the definition of "loose". It's quite
obvious to everyone, AFAICT, that the terms used in the original response
aren't C# terms that apply to the subject matter, and therefore can be
considered "loose" within a C# newsgroup.

Regardless, and what I think the actual [discussion] was about, is that you
don't think overloading terms is ambiguous, correct? (I ask regardless of
context, since the point of clarity is to reduce the amount of assumptions
that must be made in order to better understand the written material.)
 
G

garyusenet

Very interesting, one day I hope to be able to follow such scholarly
debate.

I'm going to see if I can find that book ' CLR via C# ' in the
bookshops at lunchtime (im in the UK) I haven't tried to find a
programming book in a bookshop before, so I don't know what my chances
of success will be.

If they do not have it in stock i'll order it from Google. But I want
to read it this evening!

You are all very kind,

Gary-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top