From: Bruce S. <Bru...@nc...> - 2009-09-14 15:38:40
|
Thanks for the additional background, Craig. It's good to have a card-carrying computer scientist commenting on the issues! Your point about updating a bunch of Visual objects however doesn't work, because the setters for Visual vector attributes like pos or axis make new vectors. This explains for example why you can write as a shorthand pos=(1,0,0) instead of pos=vector(1,0,0); a vector is constructed out of the triple. Here is a routine that shows the (non)effect: A = vector(0,1,0) arrow(pos=(0,0,0), axis=A) arrow(pos=(1,0,0), axis=A) scene.mouse.getclick() A = 3*A After clicking, the arrows don't get longer, because axis=A is basically axis=vector(A). In any case, it would be a rare circumstance where you wanted some vector attribute of lots of objects to be the same, and to change together. Bruce Sherwood Craig Struble wrote: > It should be pointed out that many object oriented languages share > this behavior. Java behaves the same way, for example. Many others > have pointed out the difficulties in copying objects (deep vs. shallow > copies) and bigger problems for copying arise when there are circular > references, which are common for complex data structures (e.g. general > graphs). > > The object reference behavior is useful when implementing some kinds > of data structures when you need a "trailing pointer" for updates. > Lots of linked list implementations use this approach. It's atypical > to do this in Python since it has a very rich collection of data > structures already implemented, but it can be useful. > > I would guess in VPython, this behavior could make it easier to update > the positions or movements of a large group of visual objects. If they > all refer to the same point or vector, change that vector and all the > objects change accordingly. It would be nice to make a single update > instead of having to looping over each object, which would probably be > slower. > > Craig > |