| To: | "users@xxxxxxxxxx" <users@xxxxxxxxxx> |
|---|---|
| Subject: | IDE Warning - Parameter value should not be assigned - Update |
| From: | "Edward Sumerfield" <esumerfd@xxxxxxxxx> |
| Date: | Thu, 3 Aug 2006 08:57:43 -0400 |
| Delivered-to: | mailing list users@cinjug.org |
| Domainkey-signature: | a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type; b=Coh0lYyKH+zfeEQjP5PQ8CdqqZdFcb6MZWEliJXBLfi8FhckUjWilyV3yfY0aOL6qwuoEk8lwbTdHRjrjHY6MUOk3bzkO0iPBl3iandj8whnd8Z+/Q56FZVuEXDhl4glHYHrJbvA6FwApf4WljtWnNw3BEUX7tMi6q0kvPX8Uko= |
| Mailing-list: | contact users-help@cinjug.org; run by ezmlm |
| Reply-to: | esumerfd@xxxxxxxxxxxxxx |
|
I came up with another reason to drop the rule. There is a bug in the following code but can really tell by looking at it. One would presume that the altered value should be passed to the method instead of the parameter. If the new value was distincly different then it should have a different name but if we are just trying to avoid the compiler warnings we are likley to keep them the same.
public void foo(int a_value) { int value = a_value; value++; doSomething(a_value); doSomethingElse(value); } Not sure if anyone read my blog entry on pre-bugs but this is a similar case. Ressigning parameters to local variables increases the risk of a bug and hence is a pre-bug which should be avoided. http://esumerfield.blogspot.com/2005/09/pre-bug-variable-notation.html ---------- Forwarded message ---------- From: Edward Sumerfield <esumerfd@xxxxxxxxx> Date: Aug 2, 2006 1:54 PM Subject: Re: [cinjug-users] IDE Warning - Parameter value should not be assigned To: "users@xxxxxxxxxx" <users@xxxxxxxxxx> In JDK1.5 the warning will say that newList "can only be null" which should catch that scenario.
Once we accept that the changed value can not be returned we are left with a "read only" value, expecially if we add James' final operator. So the resulting code is just redundent. public void foo(final int a_value) { int value = a_value; value++; doSomething(value); doSomethingElse(value); } To Brians' point, I agree that in most cases this problem doesn't come up and as methods are reduced in size the problem goes away. However, with short methods the "hard to follow" concern goes away aswell. There is also the counter argument that two variables is are complex than one. The hard to follow concern would be solved with good naming conventions. public void foo(int a_numberOfRulesToBreak) { a_numberOfRulesToBreak++; doSomething(a_numberOfRulesToBreak); doSomethingElse(a_numberOfRulesToBreak); } I think, given the severity of the problem, that this warning should now be ignored. Less code is better. This means I am agreeing with Rob the Ruby guy. See you at NoFluff dude. :-)
On 8/2/06, Joe Fox <joe.fox@xxxxxxxxxxxx> wrote: -----BEGIN PGP SIGNED MESSAGE----- -- Ed -- Ed |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | want to meet?, Michael |
|---|---|
| Next by Date: | :SPAM: Herb That Was Once Banned is Back!, Best Weightloss |
| Previous by Thread: | want to meet?, Michael |
| Next by Thread: | Dr YOUR NAME, how does that sounds?, Online Degrees Newsletter |
| Indexes: | [Date] [Thread] [Top] [All Lists] |