From: Keith Thompson on
Arne Vajhøj <arne(a)vajhoej.dk> writes:
[...]
> Anyone that has read "Java for absolute beginners" know that
> int's in Java are not objects and use the exact same number
> of bytes as C (on platforms where C int is 4 byte).
[...]

Since this is cross-posted to comp.lang.java.programmer and
comp.lang.c, let me clarify that point.

C defines an "object" as a "region of data storage in the execution
environment, the contents of which can represent values". This has
nothing to do with object-oriented programming. Thus a declared
variable of type int certain is an "object" if you use the C
definition of the term. (Note that C++ uses a very similar
definition.)

I don't know how "Java" defines the term.

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Lew on
Keith Thompson wrote:
> Arne Vajhøj <arne(a)vajhoej.dk> writes:
> [...]
>> Anyone that has read "Java for absolute beginners" know that
>> int's in Java are not objects and use the exact same number
>> of bytes as C (on platforms where C int is 4 byte).
> [...]
>
> Since this is cross-posted to comp.lang.java.programmer and
> comp.lang.c, let me clarify that point.
>
> C defines an "object" as a "region of data storage in the execution
> environment, the contents of which can represent values". This has
> nothing to do with object-oriented programming. Thus a declared
> variable of type int certain is an "object" if you use the C
> definition of the term. (Note that C++ uses a very similar
> definition.)
>
> I don't know how "Java" defines the term.

That may be, but the context to which Arne replied and that you excised
claimed that Java has tons of memory overhead to represent an 'int' by virtue
of being an object, which is a bloody falsehood. Clearly that poster was
using "object" in the current conventional computer-programming sense of the
word, and not in your more specialized frame.

FYI, and it absolutely freaking *ASTOUNDS* me that anyone presuming to call
themselves a programmer today has not gotten familiar with object-oriented
programming at least enough to know what an object is, I mean, come on,
already! - an object in Java is exactly what it is in any object-oriented
programming environment. Roughly it's a struct with built-in functions.

You really should expand your study. Start with the Wikipedia definition,
perhaps read Grady Booch. Being a C programmer is not a good excuse. In
fact, it's no excuse at all.

--
Lew
From: Keith Thompson on
Lew <noone(a)lewscanon.com> writes:
> Keith Thompson wrote:
>> Arne Vajhøj <arne(a)vajhoej.dk> writes:
>> [...]
>>> Anyone that has read "Java for absolute beginners" know that
>>> int's in Java are not objects and use the exact same number
>>> of bytes as C (on platforms where C int is 4 byte).
>> [...]
>>
>> Since this is cross-posted to comp.lang.java.programmer and
>> comp.lang.c, let me clarify that point.
>>
>> C defines an "object" as a "region of data storage in the execution
>> environment, the contents of which can represent values". This has
>> nothing to do with object-oriented programming. Thus a declared
>> variable of type int certain is an "object" if you use the C
>> definition of the term. (Note that C++ uses a very similar
>> definition.)
>>
>> I don't know how "Java" defines the term.

And I don't know why I put quotation marks around "Java".

> That may be, but the context to which Arne replied and that you
> excised claimed that Java has tons of memory overhead to represent an
> 'int' by virtue of being an object, which is a bloody falsehood.

And I'm sure that Arne was correct and the previous poster was wrong
on that point. That just didn't happen to be what I was commenting
on.

> Clearly that poster was using "object" in the current conventional
> computer-programming sense of the word, and not in your more
> specialized frame.

Yes, clearly. But he did so in an article posted to comp.lang.c.

> FYI, and it absolutely freaking *ASTOUNDS* me that anyone presuming to
> call themselves a programmer today has not gotten familiar with
> object-oriented programming at least enough to know what an object is,
> I mean, come on, already! - an object in Java is exactly what it is in
> any object-oriented programming environment. Roughly it's a struct
> with built-in functions.

What makes you think I'm not familiar with object-oriented
programming?

I was making a relatively narrow point, that the term "object" can
have more than one meaning. Since this thread is cross-posted to
comp.lang.c (where we tend to use the C standard's definition of
"object") and comp.lang.java.programmer (where, quite reasonably,
I'm sure they use the Java definition of the term), I thought it
was a point worth making.

I just checked the Java language definition:
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3.1
An _object_ is a _class instance_ or an array.
So yes, an int variable in Java is not an "object" in the way that
Java defines the term. I'm not at all surprised to learn that,
nor did I say anything that implies otherwise.

And, as I mentioned, C++ (which is often considered to be an
object-oriented language) has a definition of "object" that's very
similar to the C definition; in C++, a variable of type int *is*
an object.

> You really should expand your study. Start with the Wikipedia
> definition, perhaps read Grady Booch. Being a C programmer is not a
> good excuse. In fact, it's no excuse at all.

Excuse for what? (And I happen to program in C++ for a living;
I just don't discuss C++ in comp.lang.c.)

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Keith Thompson on
ram(a)zedat.fu-berlin.de (Stefan Ram) writes:
> Keith Thompson <kst-u(a)mib.org> writes:
>>in C++, a variable of type int *is* an object.
>
> No, in C++ an object is a region of storage, while a variable
> is introduced by the /declaration/ of an object. You can have
> undeclared objects in C++, which thus are objects, but not variables.

Ok. I was using the term "variable" in an informal sense. The C
standard in particular doesn't define the term, and only rarely
uses it.

> In Java, »variable« has yet another meaning, which corresponds
> to the meaning of »object« in C and C++.

The lesson, I think, is that you have to be very careful even with
(or especially with) seemingly fundamental and obvious terms like
"object", "variable", and so forth. They can have different meanings
in different contexts. The meaning of "object" in C and C++ is
clear and unambiguous. The meaning of "object" in Java is likewise
clear and umambiguous. They're just very different meanings.

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Arved Sandstrom on
Keith Thompson wrote:
> ram(a)zedat.fu-berlin.de (Stefan Ram) writes:
>> Keith Thompson <kst-u(a)mib.org> writes:
>>> in C++, a variable of type int *is* an object.
>> No, in C++ an object is a region of storage, while a variable
>> is introduced by the /declaration/ of an object. You can have
>> undeclared objects in C++, which thus are objects, but not variables.
>
> Ok. I was using the term "variable" in an informal sense. The C
> standard in particular doesn't define the term, and only rarely
> uses it.
>
>> In Java, »variable« has yet another meaning, which corresponds
>> to the meaning of »object« in C and C++.
>
> The lesson, I think, is that you have to be very careful even with
> (or especially with) seemingly fundamental and obvious terms like
> "object", "variable", and so forth. They can have different meanings
> in different contexts. The meaning of "object" in C and C++ is
> clear and unambiguous. The meaning of "object" in Java is likewise
> clear and umambiguous. They're just very different meanings.
>
Maybe I'm missing something here, but I fail to see how the meaning of
"object" is all that different between C++ and Java. In both cases it's
an instance of a class, which means they are also regions of storage.

The relevant difference as I see it is that in Java object variables are
references - declaring one does not create an object and it doesn't
even necessarily point to one. Copying a reference simply copies the
reference. Whereas in C++ an object variable actually _is_ an object -
the variable declaration calls the ctor, and copying creates a new object.

The meaning of "variable" in Java does not correspond to the meaning of
"object" in C++, not in any meaningful way. A Java object reference - a
variable - that *has been initialized* provides a way of accessing the
object storage by reference, and if anything a C++ pointer to an object
is closer to that idea, since it's not tied to any particular object.

AHS