What's wrong with my logic here?
Posted
by stu
on Stack Overflow
See other posts from Stack Overflow
or by stu
Published on 2010-04-13T18:12:11Z
Indexed on
2010/04/13
18:13 UTC
Read the original article
Hit count: 323
efficiency
|logic
In java they say don't concatenate Strings, instead you should make a stringbuffer and keep adding to that and then when you're all done, use toString() to get a String object out of it. Here's what I don't get. They say do this for performance reasons, because concatenating strings makes lots of temporary objects. But if the goal was performance, then you'd use a language like C/C++ or assembly.
The argument for using java is that it is a lot cheaper to buy a faster processor than it is to pay a senior programmer to write fast efficient code. So on the one hand, you're supposed let the hardware take care of the inefficiencies, but on the other hand, you're supposed to use stringbuffers to make java more efficient.
While I see that you can do both, use java and stringbuffers, my question is where is the flaw in the logic that you either use a faster chip or you spent extra time writing more efficient software.
© Stack Overflow or respective owner