Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!newsfeed1.swip.net!uio.no!ntnu.no!not-for-mail From: Bent C Dalager Newsgroups: comp.lang.java.help Subject: Re: Why would one use += 1 at the place of ++? Date: Thu, 19 May 2011 10:22:54 +0000 (UTC) Organization: Norwegian university of science and technology Lines: 25 Message-ID: References: <8762p7upgn.fsf@merciadriluca-station.MERCIADRILUCA> NNTP-Posting-Host: microbel.pvv.ntnu.no X-Trace: orkan.itea.ntnu.no 1305800574 21498 129.241.210.179 (19 May 2011 10:22:54 GMT) X-Complaints-To: usenet@ntnu.no NNTP-Posting-Date: Thu, 19 May 2011 10:22:54 +0000 (UTC) User-Agent: slrn/pre1.0.0-18 (Linux) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:690 On 2011-05-19, Merciadri Luca wrote: > > Hi, > > I've heard that it is generally better to use += 1 at the place of ++. Could this be advice based on C++ experience rather than Java? In C++ I understand the two behave rather differently even if the result of the calculation is often the same. In particular "x++" may have some slight overhead issues in C++ in that the compiler will need to keep a temporary copy of the original state of "x" until the entire statement has been evaluated. I have seen people advocate the use of "++x" in its stead for this reason, when the difference otherwise doesn't matter. In Java the only issue I can see is if you don't understand the difference between ++x and x++, in which case you may want to use x += 1 until you have read up some more on the ++ operator. Cheers, Bent D -- Bent Dalager - bcd@pvv.org - http://www.pvv.org/~bcd powered by emacs