generic-github-user / Caesium

General-purpose AI library with NEAT-style genetic algorithm.
https://generic-github-user.github.io/Caesium/src/versions/javascript/projects/network-visualization/
MIT License
1 stars 1 forks source link

Clone networks or use immutable objects? #91

Closed generic-github-user closed 5 years ago

generic-github-user commented 5 years ago

This is a pretty important decision, as it will affect the way code for this program is written for the foreseeable future.

See #87 and #89.

generic-github-user commented 5 years ago

Both cloning and freezing could use Object.freeze() . . . but an object that is being cloned should not be frozen in case the original object needs to be modified.

generic-github-user commented 5 years ago

I've been trying to figure this out for three days now . . .

generic-github-user commented 5 years ago

Maybe create a pros and cons list for each option . . .

generic-github-user commented 5 years ago

I think for now I will keep using a mutable data structure, until the scale of the project is large enough that this requires a different solution. I'm not entirely ruling out using an immutable data structure in the future, but it seems impractical at this time.

generic-github-user commented 5 years ago

The network objects will be deep cloned with JSON.parse(JSON.stringify()) and their methods will be added automatically.

generic-github-user commented 5 years ago

See this comment: https://github.com/generic-github-user/Caesium/issues/87#issuecomment-414640554

generic-github-user commented 5 years ago

Looks like we will actually be using an immutable data structure . . . references within network objects being cloned are causing issues: #92

generic-github-user commented 5 years ago

Wow, algorithms using mutable objects apparently run much faster than algorithms using immutable objects: https://stackoverflow.com/a/41432408