phetsims / resistance-in-a-wire

"Resistance in a Wire" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/resistance-in-a-wire
GNU General Public License v3.0
1 stars 4 forks source link

Code Review for phet-io instrumentation #79

Closed zepumph closed 7 years ago

zepumph commented 7 years ago

NOTE! Prior to doing a code review, copy this checklist to a GitHub issue for the repository being reviewed.

PhET code-review checklist

Build and Run Checks

Internationalization

Repository structure

   my-repo/
      assets/
      audio/
         license.json
      doc/
         model.md
         implementation-notes.md
      images/
         license.json
      js/
         (see section below)
      dependencies.json
      .gitignore
      my-repo_en.html
      my-repo-strings_en.json
      Gruntfile.js
      LICENSE
      package.json
      README.md

For a common-code repository, the structure is similar, but some of the files and directories may not be present if the repo doesn’t have audio, images, strings, or a demo application.

   my-repo/
      js/
         common/
            model/
            view/
         introduction/
            model/
            view/
         lab/
            model/
            view/
         my-repo-config.js
         my-repo-main.js
         myRepo.js

Coding conventions

Documentation

Math Libraries

Organization, Readability, Maintainability

Performance, Usability

// Cap large dt values, which can occur when the tab containing
// the sim had been hidden and then re-shown
dt = Math.min( 0.1, dt );

Memory Leaks

PhET-iO

zepumph commented 7 years ago

@samreid do these credits seem alright to you?

credits: {
  leadDesign: 'Michael Dubson',
  softwareDevelopment: 'Michael Dubson, John Blanco',
  team: 'Wendy Adams, Mindy Gratny, Ariel Paul',
  thanks: 'Thanks to Mobile Learner Labs for working with the PhET development team\nto convert this simulation to HTML5.'
}
samreid commented 7 years ago

The credits seem reasonable, nothing unexpected jumping out at me.

zepumph commented 7 years ago

For each common-code component (sun, scenery-phet, vegas, …) that opaquely registers observers or listeners, is there a call to that component’s dispose function, or documentation about why dispose is unnecessary?

There is no dispose function for the ResistanceInAWireScreenView, but there is this call:

    this.addChild( new ResetAllButton( {
      listener: function() { model.reset(); },
      radius: 30,
      right: slidersBox.right,
      centerY: slidersBox.bottom + 60
    } ) );

I don't think more has to be done here, but there is no documentation about that listener being removed.

zepumph commented 7 years ago

@samreid there are just a few points I want to go over with you, otherwise this issue is basically complete.

zepumph commented 7 years ago

@samreid please close if you feel like all looks good.

samreid commented 7 years ago

I did some more refactoring in the above commits, SlidersBox still needs attention.

zepumph commented 7 years ago

@samreid in https://github.com/phetsims/resistance-in-a-wire/commit/588c5ce7900b8eea7cd4b32dc16f5df46b6a0e57 I noticed that you moved the Node.call() down to the end of the constructor. I am thinking that that is because the tandem must be passed as the last thing in the constructor.

Could you comment on your implementation vs:

function Slider(){

  Node.call( {x:x, y:y . . .}

... all of the constructor

  Node.mutate( {tandem: tandem})
samreid commented 7 years ago

I am thinking that that is because the tandem must be passed as the last thing in the constructor.

No, the tandem doesn't need to be last. The main reason for the change was to move from an imperative style to a declarative style. Here's a simplification of the change:

// imperative
var x = new Node();
x.addChild(child1);
x.addChild(child2);

// declarative
var y = new Node({
  children: [child1, child2]
});

The main principles for why to prefer the 2nd approach:

  1. It is preferable to create the node with its correct state rather than creating it in the incorrect state and mutating it over a period of time.
  2. Less opportunity for other code/bugs to sneak in between the addChild calls
  3. Factoring out the addChild calls
  4. Easy to see the structure of the node (more relevant when there are many lines of code between the addChild calls.

It is not always possible to use the declarative approach, but it seems generally preferable where applicable.

zepumph commented 7 years ago

@veillette did some great work on this front. I think it still needs another pass to make sure all is good. But I think we are close.

zepumph commented 7 years ago

@samreid I think this is ready to close, I refactored further and got things pretty crisp and clean. Please have a look and comment if there is more to be done. Thanks!

samreid commented 7 years ago

Things look much better, thanks! Closing.