[Python-ideas] aliasing
Bruce Leban
bruce at leapyear.org
Thu Sep 1 17:38:57 CEST 2011
On Thu, Sep 1, 2011 at 6:19 AM, Peio Borthelle <peio.borthelle at gmail.com>wrote:
>
> I don't agree with you when you say there is no necessary use case, e.g. I
> have two images in a gui and they must stay at the same position (relatively
> one to the other) but follow the movements of the arrow keys
> (truthful!). You can't do it by using an intermediate list because the list
> object is mutable but his data not:
> ------------------------
> >>> list = [3,]
> >>> a = list[0]
> >>> list[0] = 6
> >>> a
> 3
>
This little snippet is unsurprising and would be extremely surprising if it
printed 6 instead.
> -------------------------
> I really don't see any other solution, even I'm sure it would be a twisted
> operation and I don't find it very pythonic...
>
>
If you don't see any other solution than you're not looking hard enough.
What you're saying is you have objects in a gui which must be manipulated by
simple variables rather than be encapsulated in a class. I don't buy it. How
does this work with N objects which must lock together? I note that you say
"relative to one another" so what you really mean is x2 locks to x1 + A and
y2 locks to x1 + B. That's not a simple alias. Can I assign to x2? If you
think assigning to x2 will change x1, you haven't thought it through. If you
think it won't but instead will break the alias, then what is the advantage
of not just writing x2()?? You save two characters (and a lambda somewhere
else) at the expense of making the code much harder to understand. It's like
a programmer building a spreadsheet app in Python saying this is the only
way he can implement cell recalc.
Fortran has a statement called COMMON which aliases variables. It's useful
for reshaping arrays. Other than that, it's an easy way to confuse
programmers and the compiler.
--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110901/dbc77917/attachment.html>
More information about the Python-ideas
mailing list