Java is lame yet again
Nov. 15th, 2006 03:44 pmThings to hate about Java, #5801:
I get why Java has both Strings and StringBuffers. There are advantages to each, and times when you want to use one rather than the other.
Like, if you're building a long string up out of a lot of little pieces, it's a whole lot more efficient to do it with a StringBuffer, which is designed for that kind of thing, than do it with Strings, because they're immutable and the '+' operator gets translated invisibly into a temporary StringBuffer and some calls to append(), so why not do it that way explicitly in the first place, right?
So, given that the number-one usage of StringBuffer is almost certain to be to concatenating a bunch of Strings together, and given that StringBuffer is just as much a part of the Java language core as String, and given that you can use the '+' and '+=' operators on Strings...
Why in the name of all that is holy is '+=' NOT aliased to 'append()' for StringBuffers?
Argh, I say. Argh.
I get why Java has both Strings and StringBuffers. There are advantages to each, and times when you want to use one rather than the other.
Like, if you're building a long string up out of a lot of little pieces, it's a whole lot more efficient to do it with a StringBuffer, which is designed for that kind of thing, than do it with Strings, because they're immutable and the '+' operator gets translated invisibly into a temporary StringBuffer and some calls to append(), so why not do it that way explicitly in the first place, right?
So, given that the number-one usage of StringBuffer is almost certain to be to concatenating a bunch of Strings together, and given that StringBuffer is just as much a part of the Java language core as String, and given that you can use the '+' and '+=' operators on Strings...
Why in the name of all that is holy is '+=' NOT aliased to 'append()' for StringBuffers?
Argh, I say. Argh.
no subject
Date: 2006-11-15 10:52 pm (UTC)Since Java is all passed by-value,
a += bdoesn't modify in place, but is really just shorthand fora = a + bAnd when a is a StringBuffer and b is a String, that turns into
a = a.toString().concat(b)which is what you're trying to avoid in the first place.
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2006-11-16 02:23 am (UTC)And discover the joys of unintended side effects.
no subject
Date: 2006-11-16 09:27 am (UTC)Oh, wait, no. Use Python!
no subject
Date: 2006-11-16 05:53 pm (UTC)And discover the joys of unintended side effects."
Oh, I would *so* go back and re-learn Java if it were Beemerized: just think of all the wise and unique things it could do...and, as a bonus, it would have a really cool mustache...