Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: some personal rambling on java the lang

Reply
Thread Tools

Re: some personal rambling on java the lang

 
 
Stefan Ram
Guest
Posts: n/a
 
      10-15-2010
Patricia Shanahan <(E-Mail Removed)> writes:
>Joshua Maurice wrote:
>>again conclude that Java did a disservice by using the term
>>"reference" instead of the well known term "pointer".

>Agreed. I think Sun made a bad choice in moving in the direction of
>muddled terminology, rather than going for clarity and education.


Sun /did/ use the term pointer:

»(...) reference values (...) are pointers«

JLS3, 4.3.1.

However, this is another meaning of »pointer« than in C,
where pointers are not values, but variables (which are
called »objects« in C):

»A pointer type describes an object whose value provides
a reference to an entity of the referenced type.«

ISO/IEC 9899:1999 (E), 6.2.5, #20

So, matching up terms from different languages is a difficult
business where it does not matter much if the same words
are used or not. (Strictly, C does nowhere define »pointer«
nor »pointer type«, but only says what a pointer type
»describes« - a wording too vague for my taste.)

 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      10-15-2010
http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram) writes:
>Patricia Shanahan <(E-Mail Removed)> writes:
>>Joshua Maurice wrote:
>>>again conclude that Java did a disservice by using the term
>>>"reference" instead of the well known term "pointer".

>>Agreed. I think Sun made a bad choice in moving in the direction of
>>muddled terminology, rather than going for clarity and education.

>»(...) reference values (...) are pointers«
>JLS3, 4.3.1.
>»A pointer type describes an object whose value provides
>a reference to an entity of the referenced type.«
>ISO/IEC 9899:1999 (E), 6.2.5, #20


And, I only now observe that C uses the word »reference«
above twice to explain what a pointer type is, once as a
noun, once as a verb. So does this »muddle« the C
terminology, then?

Exaggerated, one might say that Sun explains references
as pointers, while C explains pointers as references.

 
Reply With Quote
 
 
 
 
Arne Vajhřj
Guest
Posts: n/a
 
      10-15-2010
On 15-10-2010 17:27, Stefan Ram wrote:
> (E-Mail Removed)-berlin.de (Stefan Ram) writes:
>> Patricia Shanahan<(E-Mail Removed)> writes:
>>> Joshua Maurice wrote:
>>>> again conclude that Java did a disservice by using the term
>>>> "reference" instead of the well known term "pointer".
>>> Agreed. I think Sun made a bad choice in moving in the direction of
>>> muddled terminology, rather than going for clarity and education.

>> »(...) reference values (...) are pointers«
>> JLS3, 4.3.1.
>> »A pointer type describes an object whose value provides
>> a reference to an entity of the referenced type.«
>> ISO/IEC 9899:1999 (E), 6.2.5, #20

>
> And, I only now observe that C uses the word »reference«
> above twice to explain what a pointer type is, once as a
> noun, once as a verb. So does this »muddle« the C
> terminology, then?
>
> Exaggerated, one might say that Sun explains references
> as pointers, while C explains pointers as references.




Arne
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-15-2010
(E-Mail Removed)-berlin.de (Stefan Ram) writes:
> Patricia Shanahan <(E-Mail Removed)> writes:
>>Joshua Maurice wrote:
>>>again conclude that Java did a disservice by using the term
>>>"reference" instead of the well known term "pointer".

>>Agreed. I think Sun made a bad choice in moving in the direction of
>>muddled terminology, rather than going for clarity and education.

>
> Sun /did/ use the term pointer:
>
> »(...) reference values (...) are pointers«
>
> JLS3, 4.3.1.
>
> However, this is another meaning of »pointer« than in C,
> where pointers are not values, but variables (which are
> called »objects« in C):
>
> »A pointer type describes an object whose value provides
> a reference to an entity of the referenced type.«
>
> ISO/IEC 9899:1999 (E), 6.2.5, #20
>
> So, matching up terms from different languages is a difficult
> business where it does not matter much if the same words
> are used or not. (Strictly, C does nowhere define »pointer«
> nor »pointer type«, but only says what a pointer type
> »describes« - a wording too vague for my taste.)


But the C standard also uses the word "pointer" to refer to
a *value* of pointer type. See, for example, C99 7.20.3.3p3:

The malloc function returns either a null pointer or a pointer to
the allocated space.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <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"
 
Reply With Quote
 
Joshua Maurice
Guest
Posts: n/a
 
      10-15-2010
On Oct 15, 2:18*pm, (E-Mail Removed)-berlin.de (Stefan Ram) wrote:
> Patricia Shanahan <(E-Mail Removed)> writes:
> >Joshua Maurice wrote:
> >>again conclude that Java did a disservice by using the term
> >>"reference" instead of the well known term "pointer".

> >Agreed. I think Sun made a bad choice in moving in the direction of
> >muddled terminology, rather than going for clarity and education.

>
> * Sun /did/ use the term pointer:
>
> * * * »(...) reference values (...) are pointers«
>
> * * JLS3, 4.3.1.


That does nothing to address my concern. It fact, it adds to my
concern. My concern is: Java is a derivative of C and C++, and Java
shared a lot of the common syntax and semantics of C and C++. As such,
it causes undo confusion to purposefully confuse and conflate two
formerly distinct, well defined terms.

> * However, this is another meaning of »pointer« than in C,
> * where pointers are not values, but variables (which are
> * called »objects« in C):
>
> * * * »A pointer type describes an object whose value provides
> * * * a reference to an entity of the referenced type.«
>
> * * ISO/IEC 9899:1999 (E), 6.2.5, #20
>


You cherry picked quotes, and/or the quotes are incorrect. The
terminology in this domain of discourse is loose. This probably is
because we all understand what's going on. It's like mixing up class
and object - you instantiate a class to create an object. You can't
new a class, though we all know what the speaker means. Your cherry
picked quote is an informal use of the term "value". A Java reference
is not a "value", even according to the Java standard.

What follows are the actual definitions, simplified for brevity. (I
don't want to quote an entire treatise on type theory.)

In C, objects are pieces of memory (on some abstract machine) which
hold values. A value of an object is the sequence of bits of the
object, aka the data contents of that object. Each object has a type
which constrains the allowed bit patterns of the object, and provides
a means to interpret those bit patterns, and provides operations on
those bit patterns.

In C, variables are objects which have declarations and definitions
with names in source code.
//Please forgive the C code.
//x is a variable and an object
int x;
//y is a variable and an object, *y is an object but not a variable
int* y = new int;

In C, a pointer is a somewhat vague term. A type can be a pointer (a
pointer-type). An object can be a pointer (an object of pointer-type).
A variable can be a pointer (an object of pointer-type).

Obviously, in Java the situation is slightly different because Java
defines Object to be a very particular thing, and Java defines objects
to be garbage collected entities allocated from the heap. The
definition of "value" remains largely unchanged: a value is the "bit
pattern" (simplification) of a Java object, a Java reference, or a
Java primitive. A value is the current contents of the entity, the
state of the entity.

> So, matching up terms from different languages is a difficult
> business where it does not matter much if the same words
> are used or not. (Strictly, C does nowhere define »pointer«
> nor »pointer type«, but only says what a pointer type
> »describes« - a wording too vague for my taste.)


It's only difficult in this case because Sun purposefully changed the
meaning, and their change largely broke with past definitions of the
terms. The syntax of Java references and C pointers is largely the
same, and the semantics are exactly the same. A Java reference behaves
exactly like a C pointer (except with null pointer checking and no
pointer math). It does not behave as a C++ reference, which does not
have a distinct "state" apart from the referred-to object. C++ has
pass by reference and pass by value. Java only has pass by value - but
the only things which can be passed are primitives and Java
references.

Again, my contention is that they didn't need to pick a new word which
could cause confusion when a clear and precise term, pointer, clearly
and aptly described the semantics, and again, it's only a minor
inconvenience. It's not the end of the world.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-16-2010
Joshua Maurice <(E-Mail Removed)> writes:
[...]
> In C, objects are pieces of memory (on some abstract machine) which
> hold values. A value of an object is the sequence of bits of the
> object, aka the data contents of that object. Each object has a type
> which constrains the allowed bit patterns of the object, and provides
> a means to interpret those bit patterns, and provides operations on
> those bit patterns.


Pretty much, except that an object doesn't necessarily inherently have a
type. For example, malloc() allocates memory and returns a void*
pointer to it; that memory doesn't have a type until you impose one on
it, for example by assigning the void* pointer to a some_type* pointer
(the standard uses the term "effective type".

(Note that the C++ standard's definition of "object" is very similar
to C's; a C++ "object" isn't necessarily of some class type.)

The sequence of bits is the representation of an object. The value is
an interpretation of those bits with respect to some specified type.

> In C, variables are objects which have declarations and definitions
> with names in source code.
> //Please forgive the C code.
> //x is a variable and an object
> int x;
> //y is a variable and an object, *y is an object but not a variable
> int* y = new int;


That's a perfectly reasonable definition of the word "variable", but the
C standard doesn't define or use the term.

> In C, a pointer is a somewhat vague term. A type can be a pointer (a
> pointer-type). An object can be a pointer (an object of pointer-type).
> A variable can be a pointer (an object of pointer-type).


If you think of "pointer" as an adjective, there's no vagueness;
you can have a pointer type, a pointer object, or a pointer value.
But yes, the unqualified term "pointer" is potentially ambiguous.
It most commonly refers to a pointer object, though the standard
also uses it to refer to a pointer value. (I don't think a pointer
type is commonly called a "pointer", though.) In practice this
doesn't usually cause problems; in most contexts the meaning is clear
enough, and when it isn't it's easy enough to qualify it.

[...]

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <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"
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      10-16-2010
Keith Thompson <(E-Mail Removed)> writes:
>(Note that the C++ standard's definition of "object" is very similar
>to C's; a C++ "object" isn't necessarily of some class type.)


However, just with regard to the type, C++ might have a
different concept of an object, because its specification
contains the sentence:

»An object has a type (3.9).«

1.8 »The C++ object model«, in: ISO/IEC 14882:2003(E)

This might be read to mean that /every/ object in C++ has a
type (of course, this is not necessarily a class type).

>That's a perfectly reasonable definition of the word "variable", but the
>C standard doesn't define or use the term.


It does not define, but it uses the term.

(ISO/IEC 9899:1999 (E) gives »ISO/IEC 2382-1:1993,
Information technology -- Vocabulary -- Part 1: Fundamental
terms.« as a normative reference. ISO/IEC 2382-1 indeed
defines »variable«, but in part 15, not in part 1:

»A quadruple, established by a declaration or an
implicit declaration, that consists of an identifier, a
set of data attributes, one or more addresses, and data
values, where the relationship between the addresses and
the data values may vary.«)

Regarding variables, C++ says:

»A variable is introduced by the declaration of an
object. The variable's name denotes the object.«

Oops, now I lost my self control and forgot that I DO
NOT KNOW C++, when posting to comp.lang.c. However, I
modified the Newsgroups header once again (see there).

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
some personal rambling on java the lang Xah Lee Java 101 10-24-2010 10:51 PM
objects and variables (was: some personal rambling on java the lang) Stefan Ram C++ 0 10-16-2010 01:55 AM
[A bit rambling] Open source licensing being questioned byanti-copyright types ClassCastException Java 70 06-25-2010 09:31 AM
Pythonic Nirvana - towards a true Object Oriented Environment [visionary rambling, long] Ville Vainio Python 15 07-04-2004 06:07 PM
Why I love Python (warning: rambling) KefX Python 28 04-09-2004 09:26 AM



Advertisments