lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, Dec 18, 2011 at 12:54 PM, Rebel Neurofog <> wrote:
I disagree. Although C++ isn't a language of my love it has great
operator concept.
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.