Don't know why
When I say right answer - I mean right answer to the Java language design decision to have immutable strings that appear to be mutable. Its an efficiency trap. Things that are runtime inefficient shouldn't be easy to write. This is the philosophy behind the C++ STL. You don't implement += on an iterator that has access time O(n). Its deceitful. You would implement += on an iterator that has access time O(1), that makes sense.
I feel the same way about Java's String += operator. If String is immutable, then why did you give me this little thing that appears to modify the string? Again, its deceitful.
(OT - This is one of the things that caused me to pitch C++, its inherent unpredictability. Given the wackiness of operator overloading, I was never entirely sure if a given line of code was expensive or not.)
If your goal is to incrementally build up a big string by continuously modifying some string, then what you want is a string you can modify. Declaring your container a String is bad design choice that appears to be sanctioned by the language designers since they gave you the nifty += and + operators. Its misleading.
I think your other comments had more to do with making the transition from string to text. Text is a much more complicated thing than a string.
The average hunter gatherer works 20 hours a week.
The average farmer works 40 hours a week.
The average programmer works 60 hours a week.
What the hell are we thinking?
Don't know why
When I say right answer - I mean right answer to the Java language design decision to have immutable strings that appear to be mutable. Its an efficiency trap. Things that are runtime inefficient shouldn't be easy to write. This is the philosophy behind the C++ STL. You don't implement += on an iterator that has access time O(n). Its deceitful. You would implement += on an iterator that has access time O(1), that makes sense.
I feel the same way about Java's String += operator. If String is immutable, then why did you give me this little thing that appears to modify the string? Again, its deceitful.
(OT - This is one of the things that caused me to pitch C++, its inherent unpredictability. Given the wackiness of operator overloading, I was never entirely sure if a given line of code was expensive or not.)
If your goal is to incrementally build up a big string by continuously modifying some string, then what you want is a string you can modify. Declaring your container a String is bad design choice that appears to be sanctioned by the language designers since they gave you the nifty += and + operators. Its misleading.
I think your other comments had more to do with making the transition from string to text. Text is a much more complicated thing than a string.
The average hunter gatherer works 20 hours a week.
The average farmer works 40 hours a week.
The average programmer works 60 hours a week.
What the hell are we thinking?