Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: anything like C++ references?

Reply
Thread Tools

RE: anything like C++ references?

 
 
sismex01@hebmex.com
Guest
Posts: n/a
 
      07-14-2003
> From: Tom Plunket [(E-Mail Removed)]
> 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.

 
Reply With Quote
 
 
 
 
Tom Plunket
Guest
Posts: n/a
 
      07-15-2003
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!
 
Reply With Quote
 
 
 
 
Heiko Wundram
Guest
Posts: n/a
 
      07-16-2003
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.


 
Reply With Quote
 
Stephen Horne
Guest
Posts: n/a
 
      07-16-2003
On 16 Jul 2003 07:24:30 +0200, Heiko Wundram <(E-Mail Removed)> 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).

 
Reply With Quote
 
Heiko Wundram
Guest
Posts: n/a
 
      07-17-2003
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.


 
Reply With Quote
 
Stephen Horne
Guest
Posts: n/a
 
      07-17-2003
On 17 Jul 2003 03:54:58 +0200, Heiko Wundram <(E-Mail Removed)> 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".

 
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
object-like macro used like function-like macro Patrick Kowalzick C++ 5 03-14-2006 03:30 PM
Anything like IPKall for sipgate? John Smith UK VOIP 6 09-20-2005 05:43 PM
Is there anything like Oracle ADF in other Java IDE tools ? krislioe@gmail.com Java 10 06-30-2005 03:27 PM
Re: never heard anything like it in my life? Jumbo C++ 5 01-23-2004 03:18 AM
Re: Anything like Atomica/GuruNet ? Mir Computer Support 1 08-17-2003 12:12 PM



Advertisments