RE: anything like C++ references?

Discussion in 'Python' started by sismex01@hebmex.com, Jul 15, 2003.

  1. Guest

    > From: Tom Plunket [mailto:]
    > Sent: Lunes, 14 de Julio de 2003 06:15 p.m.
    >
    > What I specifically want is a way to have a "second-level
    > binding", e.g. a reference to a reference (assuming that the
    > terminology is correct by saying that all Python variables are
    > references). This is where I see the hole in Python, that there
    > actually is a class of object that is different from everything
    > else; you can bind to anything at all in the language...except
    > references.
    >
    > -tom!
    >


    What for? What would be the practical use for such a thing?
    To rebind a name remotely? It's not very consistent with the
    rest of the language.

    To have functions which rebind a name in a hidden way seems
    to me like a veritable fountain of possible bugs. Explicit
    is better than implicit and all that.

    Those operations might have sense in a language where a variable
    name is directly related to a storage location, a memory address;
    but Python is not like that, and trying to program in that style
    in Python is quite painful.

    I find Python to be quite clear and powerful, and never have needed
    such functionality in all the different type of projects I've done,
    small-to-medium, but varied: SQL parsers, XML parsers, email
    messaging systems, GUI frontends, RPC servers and clients,
    text-formatting utilities, etc... I've never found a single
    instance where I would have needed such that.

    A binding can't also be a container, that's a job for an object,
    if you truly need to "pull" data from a code segment, then you
    should use a dictionary, or a list, or an instance of some
    other mutable class, heck, even an empty class:

    class Inbox: pass

    IB = Inbox()

    def fn(obj):
    obj.value = 25
    obj.message = "Here's a value for you"
    ... etc

    Even a scheme as simpleminded as this is infinitely better than
    having functions rebind your variable names to other objects,
    even if they're the same class.

    This, at least, is my opinion on the subject.

    -gustavo


    Advertencia:La informacion contenida en este mensaje es confidencial y
    restringida, por lo tanto esta destinada unicamente para el uso de la
    persona arriba indicada, se le notifica que esta prohibida la difusion de
    este mensaje. Si ha recibido este mensaje por error, o si hay problemas en
    la transmision, favor de comunicarse con el remitente. Gracias.
     
    , Jul 15, 2003
    #1
    1. Advertising

  2. Tom Plunket Guest

    sismex01 wrote:

    > > What I specifically want is a way to have a "second-level
    > > binding", e.g. a reference to a reference (assuming that the
    > > terminology is correct by saying that all Python variables are
    > > references).

    >
    > What for? What would be the practical use for such a thing?


    "Why would you want a bike when you have a car?"

    I would say that I wanted it because I thought it would be the
    most straight-forward solution to the problem, so I thought I'd
    ask.

    I saw the weakref docs, but it didn't seem to do what I expected
    it to do, so I asked the question. ;) At this point, I'm not
    entirely sure what use weakref has, since it seems to only
    provide the same mechanism that exists already through
    assignment.

    > To rebind a name remotely? It's not very consistent with the
    > rest of the language.


    hmm.

    def fn(b): b.val = 4

    class MyClass: pass

    a = MyClass()
    a.val = 3
    fn(a)
    print a.val

    This name was rebound remotely. I'm not trying to be difficult,
    but this does seem like much the same thing if not a bit more
    heavy-weight than what I'm asking about.

    > To have functions which rebind a name in a hidden way seems
    > to me like a veritable fountain of possible bugs. Explicit
    > is better than implicit and all that.


    and OO will never take hold, either. ;) Just look at all of the
    behind-the-scenes that's going on!

    > Those operations might have sense in a language where a variable
    > name is directly related to a storage location, a memory address;
    > but Python is not like that, and trying to program in that style
    > in Python is quite painful.


    That's why I'm not trying to program in that style, but in a new
    style that seems to me to be in the Python way, if not (yet? <g>)
    supported by the language.

    > I find Python to be quite clear and powerful, and never have needed
    > such functionality in all the different type of projects I've done,
    > small-to-medium, but varied: SQL parsers, XML parsers, email
    > messaging systems, GUI frontends, RPC servers and clients,
    > text-formatting utilities, etc... I've never found a single
    > instance where I would have needed such that.


    I've never needed the subtraction operator, myself. Every time I
    used it, I could have used a negate and an add, but I used the
    subtraction operator instead.

    Just because functionality isn't strictly needed doesn't mean
    it's not useful.


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

  3. On Tue, 2003-07-15 at 06:27, Stephen Horne wrote:
    > Really. Is that what dictionaries are for? Or lists? Or other mutable
    > classes?


    I guess that's what classes are for... Just on a personal note, I've
    never ever needed or wished for something similar to pointer syntax in
    Python. Don't you tell that it's my background, I come from a C++
    background, and have switched to Python only for the last two years or
    so.

    If you encapsulate your data correctly (have classes handle data that
    belongs together, and not pass it round in parts), everything works out
    great, at least for me. And I guess there's nothing more important than
    thinking about proper data-encapsulation before starting a project.

    All-beating-about-the-bush-for-nothing'ly,

    Heiko Wundram.
     
    Heiko Wundram, Jul 16, 2003
    #3
  4. On 16 Jul 2003 07:24:30 +0200, Heiko Wundram <> wrote:

    >If you encapsulate your data correctly (have classes handle data that
    >belongs together, and not pass it round in parts), everything works out
    >great, at least for me. And I guess there's nothing more important than
    >thinking about proper data-encapsulation before starting a project.


    The pointer thing was raised in the context of a larger discussion. It
    *would* be necessary if another change was made (don't worry, it won't
    happen).
     
    Stephen Horne, Jul 16, 2003
    #4
  5. On Wed, 2003-07-16 at 22:02, Stephen Horne wrote:
    > The pointer thing was raised in the context of a larger discussion. It
    > *would* be necessary if another change was made (don't worry, it won't
    > happen).


    I know the broader discussion context, but if changes like those (e.g.
    copy on write) were to happen at some further point in time, that would
    definitely be the moment for me to stop using Python, and switch to
    Ruby.

    Python's data model is good as it is, I don't really see the need to add
    more to it. We've gone a long way with type-class unification, and I
    guess there won't be much more need to change for very long...

    Heiko.
     
    Heiko Wundram, Jul 17, 2003
    #5
  6. On 17 Jul 2003 03:54:58 +0200, Heiko Wundram <> wrote:

    >On Wed, 2003-07-16 at 22:02, Stephen Horne wrote:
    >> The pointer thing was raised in the context of a larger discussion. It
    >> *would* be necessary if another change was made (don't worry, it won't
    >> happen).

    >
    >I know the broader discussion context, but if changes like those (e.g.
    >copy on write) were to happen at some further point in time, that would
    >definitely be the moment for me to stop using Python, and switch to
    >Ruby.


    I already said a long time ago that these weren't serious suggestions
    for Python. I used words something like "python wouldn't be python any
    more" and "in an alternative universe, maybe".
     
    Stephen Horne, Jul 17, 2003
    #6
    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,071
    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:
    359
    =?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:
    500
    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,036
    Tim Roberts
    Jul 20, 2003
  5. Michael Chermside

    RE: anything like C++ references?

    Michael Chermside, Jul 14, 2003, in forum: Python
    Replies:
    2
    Views:
    263
    Michael Hudson
    Jul 15, 2003
Loading...

Share This Page