Re: some personal rambling on java the lang

Discussion in 'C Programming' started by Stefan Ram, Oct 15, 2010.

  1. Stefan Ram

    Stefan Ram Guest

    Patricia Shanahan <> 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.)
    Stefan Ram, Oct 15, 2010
    #1
    1. Advertising

  2. Stefan Ram

    Stefan Ram Guest

    -berlin.de (Stefan Ram) writes:
    >Patricia Shanahan <> 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.
    Stefan Ram, Oct 15, 2010
    #2
    1. Advertising

  3. Stefan Ram

    Arne Vajhøj Guest

    On 15-10-2010 17:27, Stefan Ram wrote:
    > -berlin.de (Stefan Ram) writes:
    >> Patricia Shanahan<> 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
    Arne Vajhøj, Oct 15, 2010
    #3
  4. -berlin.de (Stefan Ram) writes:
    > Patricia Shanahan <> 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.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Oct 15, 2010
    #4
  5. On Oct 15, 2:18 pm, -berlin.de (Stefan Ram) wrote:
    > Patricia Shanahan <> 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.
    Joshua Maurice, Oct 16, 2010
    #5
  6. Joshua Maurice <> 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) <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"
    Keith Thompson, Oct 16, 2010
    #6
  7. Stefan Ram

    Stefan Ram Guest

    objects and variables (was: some personal rambling on java the lang)

    Keith Thompson <> 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).
    Stefan Ram, Oct 16, 2010
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KefX
    Replies:
    28
    Views:
    579
    Anton Vredegoor
    Apr 9, 2004
  2. Ville Vainio
    Replies:
    15
    Views:
    490
    Ville Vainio
    Jul 4, 2004
  3. ClassCastException
    Replies:
    70
    Views:
    1,507
    Bent C Dalager
    Jun 25, 2010
  4. Xah Lee
    Replies:
    101
    Views:
    1,606
    Pascal J. Bourguignon
    Oct 24, 2010
  5. Stefan Ram
    Replies:
    0
    Views:
    212
    Stefan Ram
    Oct 16, 2010
Loading...

Share This Page