Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!weretis.net!feeder1.news.weretis.net!newsfeed.CARNet.hr!garrison.bnet.hr!gregory.BNet.hr!not-for-mail From: Josip Almasi Newsgroups: comp.lang.java.programmer Subject: Re: Java blunders Date: Mon, 28 Jul 2014 22:23:18 +0200 Organization: B.net Hrvatska d.o.o. Lines: 44 Message-ID: References: <53cef75d$0$291$14726298@news.sunsite.dk> <7s6vs9p395bretqrtdvh9i6til83vfk52p@4ax.com> <53d04b5f$0$291$14726298@news.sunsite.dk> NNTP-Posting-Host: cpe-188-252-131-105.zg5.cable.xnet.hr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: gregory.bnet.hr 1406578998 2043 188.252.131.105 (28 Jul 2014 20:23:18 GMT) X-Complaints-To: abuse@globalnet.hr NNTP-Posting-Date: Mon, 28 Jul 2014 20:23:18 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:29404 On 07/24/2014 03:53 AM, Roedy Green wrote: > On Wed, 23 Jul 2014 19:55:09 -0400, Arne Vajhøj > wrote, quoted or indirectly quoted someone who said : > >> But is it a problem in real world programming? >> >> I have never seen a problem due to this. > > > The most common error is like this: > > out.println ( "the answer is " + > a + b > + "."); > > you must write that as: > > out.println ( "the answer is " + (a + b) + "."); I think you guys missed worst thing with java concatenation, and it's got nothing to do with operator. It's about how operator gets interpreted: out.println ( new StringBuffer("the answer is ").append(new StringBuffer(a + b)).append(new StringBuffer(".")); It's three new objects, all synchronized. OK I haven't read the spec for a while but that's it IIRC, spec requires it that way. And if you want to avoid the garbage, you need to StringBuilder shit = new StringBuilder(); shit.append("the answer is "); shit.append(a + b); shit.append("."); and another line to get the string. And bye bye code readability. Can I have strcat back please... ... err, with automated malloc/free if you please;) Now, if || or some other new concat op solves that, I'm all for it. Otherwise, I prefer +. Regards...