[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Can someone sell Lua 5.2.0 to me please ?
- From: Gé Weijers <ge@...>
- Date: Sun, 18 Dec 2011 17:05:09 -0800
On Sun, Dec 18, 2011 at 12:54 PM, Rebel Neurofog <firstname.lastname@example.org>
I disagree. Although C++ isn't a language of my love it has great
operator+= increases value IN-PLACE. So you just can't += immutable
(by design) object.
Same thing with strings: you may optimize string growing by reserving 2^N bytes
(where 2^(N -1) < real_size <= 2^N) on each reallocation.
So API can and should give a programmer an idea about what's inside.
Even in C++ adding a single character to a string using += can result in copying the whole string to a new buffer, an O(n) operation. There are tricks to keep the amortized complexity of your string operations from getting out of hand, such as doubling the string buffer size when you need to reallocate, but a single operations can still be slow.
Python (or Java) is not being dishonest, there is no guarantee that += completes in anything less than in time proportional to the size of the result.