On 8/29/06, Jim Jewett <[EMAIL PROTECTED]> wrote: > On 8/29/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > On 8/29/06, Josiah Carlson <[EMAIL PROTECTED]> wrote: > > > "Guido van Rossum" <[EMAIL PROTECTED]> wrote: > > > The type consistency and predictability is more important to me. > > Why is it essential that string views be a different type, rather than > an internal implementation detail, like long vs int? Today's strings > can already return a new object or an existing one which happens to be > equal. > > Is this just a matter of efficiency, or are you making a fundamental > distinction?
Sigh. Josiah just said he wouldn't dream of proposing that all string ops should return string views. You're not helping by questioning even that. The short answer is, if you don't have control over when a view on an existing string is returned and when a copy, there are easy to see worst-case behaviors that are worse than the problem they are trying to fix. For example, you'd get a whole series of problems like this one: res = [] for i in range(1000): s = " "*1000000 # a new 1MB string res.append(s[:1]) # a one-character string that is a view on s and hence keeps s alive if s[:1] were to return a view on s unconditionally the above loop would accumumate roughly 1 GB in wasted space. To fix this you'll have to add heuristics and all sorts of other things and that will complicate the string implementation and hence slow it down. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
