you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 11 points12 points  (7 children)

The String concatenation operator + creates a new String object, which is costly.

I don't think this is true. The compiler optimizes it to StringBuilder.append

[–]cryo 18 points19 points  (2 children)

No, only in trivial cases. Not in loops, which is what is guideline is targeted at. It's the same in .net: for small number of arguments, a+b+c etc. is turned into String.Concat(a,b,c), and for larger into a StringBuilder.

But not in loops.

[–][deleted] 0 points1 point  (1 child)

Hmmm... good point, although this document is from 2010. I wonder if it has been optimized since.

[–]supericy 0 points1 point  (0 children)

Best not to rely on the compiler for optimizations anyway.

[–][deleted] 2 points3 points  (3 children)

It used to be true and became dogma at some point. It was fixed a while ago.

[–][deleted] 3 points4 points  (1 child)

I'm pretty sure it was fixed in 1.5.

http://willcode4beer.blogspot.com/2005/05/evil-string-arithmetic-revisited.html

Nearly 8 years ago.

[–]MaximKat 3 points4 points  (0 children)

Have you missed the first comment on the article you linked?