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 07:50:37 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 70 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:11217 Lew wrote: (snip) >> (snip) >>>> start--; >>>> finish--; >>>> bar(start, finish); >> (snip, then I wrote) >> Well, not thrown away until after the call to bar. > Irrelevant. There's absolutely no value to storing the result because it > isn't reused. >> Does it actual notice that it isn't used other than the call to bar? (snip) > Apples and oranges. The OP's example didn't reuse the stored value. > And yes, Eclipse would complain (but only if you enable it to do so) > because you are modifying a parameter, which is what the warning > cares about. One of the advantages of call by value is that you can use the parameter as a variable, and change it when needed. > You could justify it perhaps in this case because you are using > the new value, unlike in the OP's example. But then that's > a different scenario, so not relevant here. > And why does everyone insist on putting autodecrement on a > separate line anyway? It helps avoid the problem of using two on the same line. At least in C, you shouldn't do things like: x=y[i++]+y[i++]; I will guess that it isn't a good idea in Java, either. I wouldn't always put one on a separate line, but sometimes the extra readability is worth one or two lines. > My Eclipse instance was not configured out of the box to report > this warning. So I turned the warning on. (Which the OP must have > done, eh? I would probably only do it in small methods, where it is obvious that it is used one place. For larger ones, it is too easy to forget, and then want to use the original value sometime later. > Begging the question of why if they hate the feature so much.) > You don't have to set it as an error, or even a warning if you > don't like it. (snip) > Notice that they point out that it's considered poor style. The engineering > reason behind this is that parameter assignment goes away at the end of the > method block. Well, in call by reference languages you have to be careful that you don't change something in the calling routine. It is an advantage of call by value that you can change it because the change goes away. > In the OP's example the other reason is that the assignment is unnecessary; it > doesn't help anything and increases code complexity, making it a bad idea. -- glen