audriusrudalevicius / evolutionchamber

Automatically exported from code.google.com/p/evolutionchamber
0 stars 0 forks source link

EcEconFitness.augmentScore assignment to method parameter #155

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Score is the method parameter in augmentScore and also the return value of the 
method.
During execution it's modified directly as the method parameter. Is this 
situation intentional?
In every case when the methods called the return value is used to replace the 
parameter value after the call.

score = augmentScore(.., .., score, ..);

this could lead to an unintentional behavior where the call would alter the 
variable without notice

score = augmentScore(.., .., someScore, ..);

after the call the someScore variable would be modified.

The performance impact of this code is almost insignificant but I wonder if the 
behavior is intentional. Note also that there are more similar methods with 
this exact case.

Original issue reported on code.google.com by netpr...@gmail.com on 22 Nov 2010 at 9:31

GoogleCodeExporter commented 8 years ago
"score = augmentScore(.., .., someScore, ..);

after the call the someScore variable would be modified."

No it wouldn't.  When a primitive variable is passed into a method, Java copies 
that variable.  If that copy is modified inside of the method, the original 
variable is not modified.

Original comment by mike.angstadt on 22 Nov 2010 at 2:29

GoogleCodeExporter commented 8 years ago
I stand corrected. Should have tested that before reporting :) Thanks.

Original comment by netpr...@gmail.com on 22 Nov 2010 at 3:21