phetsims / build-a-nucleus

"Build a Nucleus" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
0 stars 5 forks source link

Document or rethink usage of model-view transforms in model element #182

Closed jbphet closed 1 year ago

jbphet commented 1 year ago

Related to #165.

The model class ParticleNucleus has a model-view transform (MVT) that is used to implement some significant parts of its functionality. It is pretty unconventional to see an MVT in the model code, since the general idea in a model-view-controller architecture is that a model is this standalone entity that does its thing in some real coordinate frame (e.g. meters) or an arbitrary one (e.g. normalized 2D space where x and y range from 0 to 1) and that model information is then mapped into one or more views. The MVTs are therefore generally in the view code, not in the model code.

Seeing this during the code review created a bit of cognitive dissonance for me, but after scrutinizing it for a short while, I think I understand the intention. The NUCLEON_ENERGY_LEVEL_ARRAY_MVT is being used to create the essentially arbitrary coordinate frame in the model based on the radii of the particles, which is then used to position the particles, which allows the particles' internal movement code to implement the desired animations.

So, assuming I've understood the situation correctly, I have some suggestions for how to make this code easier for future maintainers to understand:

If I've misunderstood this, then I'd suggest thinking about why it's confusing and what could be done to make it less so.

zepumph commented 1 year ago

That makes a ton of sense to me. Thanks for the thoughtful ticket and excellent suggestions. I'll take a look.

zepumph commented 1 year ago

@Luisav1 can you please review these changes and feel free to make updates.

Luisav1 commented 1 year ago

These changes look great thanks @zepumph! Closing.