RE: anything like C++ references?

Discussion in 'Python' started by Michael Chermside, Jul 14, 2003.

  1. In the (lengthy) thread "anything like C++ references?" there developed
    (yet another) huge discussion of how assignment and parameter passing
    works in Python.

    In response, Ian Bicking wrote:
    > Python is not novel in the way it deals with variables. Scheme and
    > Smalltalk, for instance, act exactly the same, as do many other
    > dynamically typed languages [...].
    > This isn't a funny little feature, this is the way all strong,
    > dynamically typed languages work.

    [...]
    > The problem you have is you are still thinking of variables as slots,
    > which is not correct. Variables in Python are bindings. Assignment
    > never copies anything, or creates anything except for changing the
    > variable to point to a different address location. *Every* Python
    > assignment (a=b) is like the C assignment (a=&b).


    I have nothing whatsoever to add to this... it is just so clearly and
    simply stated that I felt it was worth repeating. Of course, lots of
    other people said the same thing in other ways, but I felt that Ian's
    phrasing is particularly useful in explaining things to programmers
    coming from a C-style background, even if it doesn't seem to reach
    Stephen Horne.

    -- Michael Chermside
    Michael Chermside, Jul 14, 2003
    #1
    1. Advertising

  2. Michael Chermside

    Tom Plunket Guest

    Michael Chermside wrote:

    > > Assignment never copies anything, or creates anything except for
    > > changing the variable to point to a different address location.
    > > *Every* Python assignment (a=b) is like the C assignment (a=&b).

    >
    > I have nothing whatsoever to add to this... it is just so clearly and
    > simply stated that I felt it was worth repeating.


    Although I don't think that it's correct. Either a and b are
    both pointer types or they're not- but IMHO it's much more useful
    (perhaps) to C programmers to say "everything's a pointer" and
    when you say

    a = 5

    You're saying the almost-C equivalent to

    a = &5;

    If one considers that everything is a pointer, and that you
    cannot necessarily change the object that the pointer points to
    (there is no equivalent of

    *a = 5

    ), then it actually becomes (hopefully) fairly straight-forward
    to the C programmer.

    So- it would probably be more helpful to C programmers to say
    "everything is a pointer" rather than "everything is a
    reference," and then add that "there is no pointer
    dereferencing."


    -tom!
    Tom Plunket, Jul 15, 2003
    #2
    1. Advertising

  3. Stephen Horne <> writes:

    > However well you explain what Python does, that doesn't mean that it
    > is doing the right thing.


    Doesn't mean it's wrong, either.

    pointless-ly y'rs
    mwh

    --
    ARTHUR: Yes. It was on display in the bottom of a locked filing
    cabinet stuck in a disused lavatory with a sign on the door
    saying "Beware of the Leopard".
    -- The Hitch-Hikers Guide to the Galaxy, Episode 1
    Michael Hudson, Jul 15, 2003
    #3
    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. Ian Bicking

    RE: anything like C++ references?

    Ian Bicking, Jul 12, 2003, in forum: Python
    Replies:
    54
    Views:
    1,051
    Christos TZOTZIOY Georgiou
    Jul 22, 2003
  2. Dave Brueck

    Re: anything like C++ references?

    Dave Brueck, Jul 13, 2003, in forum: Python
    Replies:
    4
    Views:
    346
    =?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=
    Jul 14, 2003
  3. David McNab

    Re: anything like C++ references?

    David McNab, Jul 13, 2003, in forum: Python
    Replies:
    19
    Views:
    483
    Christos TZOTZIOY Georgiou
    Jul 18, 2003
  4. Tim Peters

    RE: anything like C++ references?

    Tim Peters, Jul 13, 2003, in forum: Python
    Replies:
    44
    Views:
    1,007
    Tim Roberts
    Jul 20, 2003
  5. Replies:
    5
    Views:
    305
    Stephen Horne
    Jul 17, 2003
Loading...

Share This Page