Thread history

From Talk:Robocode
Viewing a history listing
Jump to navigation Jump to search
Time User Activity Comment
03:36, 21 August 2018 Xor (talk | contribs) Comment text edited  
03:33, 21 August 2018 Xor (talk | contribs) Comment text edited  
03:31, 21 August 2018 Xor (talk | contribs) New reply created (Reply to Keeping AdvancedRobot instance in static field)
21:41, 20 August 2018 Enamel 32 (talk | contribs) New reply created (Reply to Keeping AdvancedRobot instance in static field)
19:38, 20 August 2018 Skilgannon (talk | contribs) New reply created (Reply to Keeping AdvancedRobot instance in static field)
02:43, 20 August 2018 Xor (talk | contribs) New reply created (Reply to Keeping AdvancedRobot instance in static field)
15:32, 19 August 2018 Enamel 32 (talk | contribs) New reply created (Reply to Keeping AdvancedRobot instance in static field)
10:45, 19 August 2018 Xor (talk | contribs) New thread created  

Keeping AdvancedRobot instance in static field

When keeping AdvancedRobot instance in static field, robot will show warning:

Static references to robots can cause unwanted behaviour with the robot using these.

However I've been using this pattern (the way robocode can't detect, and I cannot avoid as well) since the first day I write robocode. However, robocode did not mention what's wrong with this pattern. Do anyone know what's the exact meaning of this warning?

Xor (talk)10:45, 19 August 2018

I think the risk is that the static robot reference is not guaranteed to be valid after a given round, so if you don’t update the reference things may not work as expected.

Enamel 32 (talk)15:32, 19 August 2018

Yes, that's also what I guess, and since I'm updating the reference every round, I guess it would not be a problem. However, since robocode did not say what unwanted behavior it is, I'm worrying about more problems: race condition (since each round you have a new thread), GC problem (no longer a problem since robocode cleans static field each battle) and more

Xor (talk)02:43, 20 August 2018

Since you're updating it every round, why do you need it to be static?

Skilgannon (talk)19:38, 20 August 2018

Ease of access, probably. I was doing the same before my big inversion of control refactoring.

Enamel 32 (talk)21:41, 20 August 2018
 

because I’m simply making everything under a static variable, just like lazy singleton. The field itself is not static at all, but the field containing the field is static and has to be static. Diamond uses this style as well afak However the problem of static reference should happen to this style as well, since two approaches are fundamentally equivalent

Xor (talk)03:31, 21 August 2018