|
Re: Support for Indexing and Iteration Safety: msg#00350python.c++
"Mike Rovner" <mike@xxxxxxxxxxx> writes: >> >>> x = foo[10].bar >> >>> del foo[10] # erase the 10th item >> >>> print x > > What about having x a weak reference which del will reset to None. I considered that, but is that really Pythonic and unsurprising? Anyway, it's not much easier to make work than the one which copies the referenced object when its position is invalidated. >> >>> x = foo[10] >> >>> foo[10] = y >> >>> print x, y >> >> Now you'll see that x and y are always identical, because x >> refers to the place in the array where you've written the >> value of y. > > It's ok, because Python have explicit copy semantics > The list isn't the only model. Huh? How does "explicit copy semantics" change anything? What does this have to do with "the list"? >> 4. Similar problem with exposed iterators: >> change out from under you. The above could lead to a crash >> or bogus results. > > bogus results are ok because it's the same as in Python - changing a list > under loop can lead to skiping an element or visiting it twice. Yes, but it will never crash. >> know how many people care. > > I think if it will put some restriction on usage it is ok with me. Do you mean to say that it's OK to expose the user to crashes as long as we tell him what he's allowed to do, and only crash if he disobeys? -- Dave Abrahams Boost Consulting www.boost-consulting.com |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Support for Indexing and Iteration Safety: 00350, David Abrahams |
|---|---|
| Next by Date: | Re: Support for Indexing and Iteration Safety: 00350, Mike Rovner |
| Previous by Thread: | Re: Support for Indexing and Iteration Safetyi: 00350, Mike Rovner |
| Next by Thread: | Re: Support for Indexing and Iteration Safety: 00350, Mike Rovner |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |