Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: glen herrmannsfeldt Newsgroups: comp.lang.java.programmer Subject: Re: Curious compiler warning Date: Wed, 11 Jan 2012 13:25:43 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 51 Message-ID: References: NNTP-Posting-Host: H0vc4U5LIRkRHNPyGCs2dA.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/2.6.32-5-amd64 (x86_64)) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11225 Arved Sandstrom wrote: > On 12-01-10 11:03 PM, Lew wrote: >> And why does everyone insist on putting autodecrement on a separate line >> anyway? > [ SNIP ] > Lew, I do just this pretty routinely these days. All of the short forms, > actually, not just -- and ++. About the only place where I normally > leave them is in "for" control expressions; more often than not with > "while" and "do" loops I'll keep the modification of "index" variables > with incrementing/decrementing etc also in separate statements, clearly > commented if necessary, in the body of the loop. I agree. Write to make something readable, minimizing the thinking required to read and understand it. Now, there is the old C favorite: while(*s++ = *t++) ; and that might be the only statement in the routine, in which case it is pretty hard to miss. For a single statement loop, and if it fits, with indending, in much less than an 80 column line, then I might keep it all in one line. If a loop loops better on separate lines, and it doesn't otherwise complicate things, increment and decrement look nicer on separate lines. > You won't catch me doing things like > values[--i] > or > b = (a += 3) > even. > The reason I don't do anything like this anymore is because it's not > just my code. And I've noted over the years that constructs like this > lead to defects. That's real life. People miss a nuance about when some > value is being modified, or even fail to note that it _is_ being > modified. Keeping the short-for operation on a separate line highlights > the fact that it is a modification. Sometimes you just have to consider each case, how it affects the readability. -- glen