Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Review #123

Closed
84 tasks done
samreid opened this issue May 7, 2024 · 5 comments
Closed
84 tasks done

Code Review #123

samreid opened this issue May 7, 2024 · 5 comments
Assignees

Comments

@samreid
Copy link
Member

samreid commented May 7, 2024

To familiarize myself better with the codebase, and better prepare for code review, I'll take a look around.

UPDATE:

To begin a code review, the responsible developer should:

  • Copy this checklist to a new GitHub issue titled "Code Review" and labeled dev:code-review.
  • Delete the Table of Contents section, since the links will be incorrect.
  • Complete (or delete) the Specific Instructions section.
  • Delete (or strikethrough) checklist items and sections that are not relevant.
  • Replace {{GITHUB_ISSUE_LINK}} with links to GitHub issues.
  • Assign the GitHub issue to the developer who is doing the code review.
    @samreid adds: I'll check off an item if the review of that item is complete, even if it has been moved to a side issue. The code review will be complete when all 84 tasks are checked off.

PhET Code-Review Checklist (a.k.a "CRC")

  • The responsible dev is responsible for removing the irrelevant parts
  • A checked-off item doesn't mean "no problem here", it means "it was reviewed"
  • Problems can be noted in side issues that reference this issue, or through // REVIEW comments in the code

Specific Instructions

There are 10 screens across 3 sims. We are publishing with keyboard support but without sonification or interactive description. This simulation uses 2 third party engines. Three.js for 3d rendering and p2 for physics. Review mobius usages as necessary.

GitHub Issues

The following standard GitHub issues should exist. If these issues are missing, or have not been completed, pause code
review until the issues have been created and addressed by the responsible dev.

Build and Run Checks

If any of these items fail, pause code review.

Memory Leaks

See also #168

Performance

Usability

  • Are UI components sufficiently responsive? (especially continuous UI components, such as sliders)
  • Are pointer areas optimized, especially for touch? (run with query parameter showPointerAreas). UPDATE: Will be addressed in review of pointer areas #170
  • Do pointer areas overlap? (run with query parameter showPointerAreas) Overlap may be OK in some cases, depending
    on the z-ordering (if the front-most object is supposed to occlude pointer areas) and whether objects can be moved. UPDATE: Will be addressed in review of pointer areas #170

Internationalization

  • Does the sim behave correctly with dynamic layout, to support dynamic locale? Run with stringTest=dynamic and
    use the left/right arrow keys.
  • Are there any strings that are not internationalized, and does the sim layout gracefully handle internationalized
    strings that are shorter than the English strings? (run with query parameter stringTest=X. You should see nothing
    but 'X' strings.)
  • Does the sim layout gracefully handle internationalized strings that are longer than the English strings? (run
    with query parameters stringTest=double and stringTest=long)
  • Does the sim stay on the sim page (doesn't redirect to an external page) when running with the query parameter
    stringTest=xss? This test passes if sim does not redirect, OK if sim crashes or fails to fully start. Only test on
    one desktop platform. For PhET-iO sims, additionally test ?stringTest=xss in Studio to make sure i18n strings didn't
    leak to phetioDocumentation, see https://github.com/phetsims/phet-io/issues/1377
  • Avoid using concatenation to create strings that will be visible in the user interface. Use StringUtils.fillIn
    and a string pattern to ensure that strings are properly localized. This is relevant in cases where order should be
    translatable.
  • Use named placeholders (e.g. "{{value}} {{units}}") instead of numbered placeholders (e.g. "{0} {1}").
  • Inspect ${REPO}-strings_en.json and verify that all string keys conform #183
    to string key conventions. String
    keys are difficult to change after a sim has been published, and they appear in the PhET-iO API (and Studio) as the
    phetioIDs for StringProperties.
  • If the sim was already released, make sure none of the original string keys have changed. If they have changed,
    make sure any changes have a good reason and have been discussed with @jbphet (it is likely that an issue
    like Translations will lose some strings the next time this is published off of master gravity-force-lab#166 should be created). UPDATE: @zepumph investigated this in missingStringPhetioElements "density.general.model.strings.densityBuoyancyCommon.averageStringProperty" #175 (comment)

Repository Structure

  • The repository name should correspond to the sim title. For example, if the sim title is "Wave Interference", then
    the repository name should be "wave-interference".

  • Are all required files and directories present? For a sim repository named “my-repo”, the general structure should
    look like this (where assets/, images/, mipmaps/ or sounds/ may be omitted if the sim doesn’t have those types of
    resource files).

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

    *Any images used in model.md or implementation-notes.md should be added here. Images specific to aiding with
    documentation do not need their own license.

  • Verify that the same image file is not present in both images/ and mipmaps/. If you need a mipmap, use it for all
    occurrences of the image.

  • Is the js/ directory properly structured? All JavaScript source should be in the js/ directory. There should be a
    subdirectory for each screen (this also applies for single-screen sims, where the subdirectory matches the repo name).
    For a multi-screen sim, code shared by 2 or more screens should be in a js/common/ subdirectory. Model and view code
    should be in model/ and view/ subdirectories for each screen and common/. For example, for a sim with screens
    “Introduction” and “Lab”, the general directory structure should look like this:

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

UPDATE: We discussed this in #125 and approved a variation

  • Do filenames use an appropriate prefix? Some filenames may be prefixed with the repository name,
    e.g. MolarityConstants.js in molarity. If the repository name is long, the developer may choose to abbreviate the
    repository name, e.g. EEConstants.js in expression-exchange. If the abbreviation is already used by another
    repository, then the full name must be used. For example, if the "EE" abbreviation is already used by
    expression-exchange, then it should not be used in equality-explorer. Whichever convention is used, it should be used
    consistently within a repository - don't mix abbreviations and full names. The abbreviation should be all uppercase
    letters; e.g. MOTHAConstants, not MotHAConstants for "Model of the Hydrogen Atom".
  • Is there a file in assets/ for every resource file in sound/ and images/? #285 Note that there is not necessarily a Is there a file in assets/ for every resource file in sound/ and images/? #285
    1:1 correspondence between asset and resource files; for example, several related images may be in the same .ai file.
    Check license.json for possible documentation of why some resources might not have a corresponding asset file.
  • For simulations, was the README.md generated by grunt published-README or grunt unpublished-README? Common
    code repos can have custom README files.
  • Is the LICENSE file correct? (Generally GPL v3 for sims and MIT for common code,
    see this thread for additional information).
    Note that "common" repos that are mostly sim-specific code (like circuit-construction-kit-common and
    density-buoyancy-common) should be GPL v3,
    see other thread.
  • Does .gitignore match the one in simula-rasa?
  • In GitHub, verify that all non-release branches have an associated issue that describes their purpose.
  • Are there any GitHub branches that are no longer needed and should be deleted?
  • Sim-specific query parameters (if any) should be identified and documented in one .js file in js/common/ or js/ (
    if there is no common/). The .js file should be named {{PREFIX}}QueryParameters.js, for example
    ArithmeticQueryParameters.js for the arithmetic repository, or FBQueryParameters.js for Function Builder (where
    the FB prefix is used).
  • Query parameters that are public-facing should be identified using public: true in the schema.
  • All sims should use a color file named MyRepoColors.ts or, if using abbreviations, MRColors.ts, and
    use ProfileColorProperty where appropriate, even if they have a single (default) profile (to support color editing
    and PhET-iO Studio). The ColorProfile pattern was converted to *Colors.ts files in
    PhET-iO instrumentation for ColorProfile scenery-phet#515. Please see
    GasPropertiesColors.ts
    for a good example.
  • Sim-specific preferences (which appear in the Simulation tab of the Preferences dialog) should appear as
    Properties in
    {{PREFIX}}Preferences.ts, for example KeplersLawsPreferences.ts. The initial value of each such preferences Property
    should be set via a query parameter from {{PREFIX}}QueryParameters.js.
  • Does package.json refer to any dependencies that are not used by the sim?
  • Does include any config that was only needed for development? For example #286
    • Lint rules turned off or made more graceful
    • Certain testing or simFeatures turned off with flags

Coding Conventions

  • Are coding conventions outlined in
    PhET's Coding Conventions document
    followed and adhered to? This document deals with PhET coding conventions. You do not need to exhaustively check every
    item in this section, nor do you necessarily need to check these items one at a time. The goal is to determine whether
    the code generally meets PhET standards.

TypeScript Conventions

Math Libraries

  • DOT/Utils.toFixed or DOT/Utils.toFixedNumber should be used instead of toFixed. JavaScript's toFixed is
    notoriously buggy. Behavior differs depending on browser, because the spec doesn't specify whether to round or floor.

IE11

  • IE is no longer supported. With that in mind remove IE-specific workarounds
  • Use string.includes and string.startsWith where possible.

Organization, Readability, and Maintainability

  • Does the organization and structure of the code make sense? Do the model and view contain types that you would
    expect (or guess!) by looking at the sim? Do the names of things correspond to the names that you see in the user
    interface?
  • Are appropriate design patterns used?
    See phet-software-design-patterns.md.
    If new or inappropriate patterns are identified, create an issue.
  • Is inheritance used where appropriate? Does the type hierarchy make sense?
  • Is composition favored over inheritance where appropriate?
    See https://en.wikipedia.org/wiki/Composition_over_inheritance.
  • Is there any unnecessary coupling? (e.g., by passing large objects to constructors, or exposing unnecessary
    properties/functions). If you only need a few fields from a large object, pass them in as separate parameters. The
    threshold for the number of parameters is up to you - use your judgement. Alternatively in TypeScript, you can
    decouple by narrowing the API using Pick, but this is a bit of a hack. Here's an example:
class MyClass {
  public constructor( tickMarksVisibleProperty: Property<boolean>,
                      model: Pick<IntroModel, 'changeWaterLevel'>, // <-- Note the call site can pass the whole model, but we declare we will only use this part of it
                      waterCup: WaterCup, modelViewTransform: ModelViewTransform2,
                      providedOptions?: WaterCup3DNodeOptions ) {}
}
  • Is there too much unnecessary decoupling? (e.g. by passing all of the properties of an object independently
    instead of passing the object itself)?
  • Are the source files reasonable in size? Scrutinize large files with too many responsibilities - can
    responsibilities be broken into smaller delegates? To see file sizes for TypeScript sims, run this shell command:
cd {{repo}}/js ; wc -l `find . -name "*.ts" -print` | sort

Accessibility

This section may be omitted if the sim has not been instrumented with accessibility features. Accessibility includes
various features, not all are always include. Ignore sections that do not apply.

General

Alternative Input

  • Does the sim pass an accessibility fuzz test? (run with query parameters fuzzBoard&ea)
  • Does the sim use ScreenView.pdomPlayAreaNode.pdomOrder and Screenview.pdomControlAreaNode.pdomOrder to control
    the traversal order and categorize Nodes in the PDOM? See alternative-input-quickstart-guide.md for more information.
  • Does this sim use specific keyboard shortcuts that overlap with global shortcuts? This includes the use of
    modifier keys like in Unintended zoom/keyboard behavior ratio-and-proportion#287. NOTE: There is currently no list
    of global shortcuts, and therefore no way to complete this checklist item.
    See Create a list of global keyboard shortcuts. phet-info#188.
    . UPDATE: The design did not call for any global keystrokes that I am aware of.

Interactive Description

Section deleted because Interactive Description is not supported for this publication.

PhET-iO

This section may be omitted if the sim has not been instrumented for PhET-iO, but is likely good to glance at no matter.

  • Does instrumentation follow the conventions described
    in PhET-iO Instrumentation Guide?
    This could be an extensive bullet. At the very least, be sure to know what amount of instrumentation this sim
    supports. Describing this further goes beyond the scope of this document.
  • PhET-iO instantiates different objects and wires up listeners that are not present in the PhET-branded simulation.
    It needs to be tested separately for memory leaks. To help isolate the nature of the memory leak, this test should be
    run separately from the PhET brand memory leak test. Test with a colorized Data Stream, and Studio (easily accessed
    from phetmarks). Compare to testing results done by the responsible developer and previous releases.
  • Make sure unused PhetioObject instances are disposed, which unregisters their tandems.
  • Make sure JOIST dt values are used instead of Date.now() or other Date functions. Perhaps try
    phet.joist.elapsedTime. Though this has already been mentioned, it is necessary for reproducible playback via input
    events and deserves a comment in this PhET-iO section.
  • Are random numbers using DOT/dotRandom as an imported module (not a global), and all doing so after modules are
    declared (non-statically)? For example, the following methods (and perhaps others) should not be
    used: Math.random, _.shuffle, _.sample, _.random. This also deserves re-iteration due to its effect on
    record/playback for PhET-iO.
  • Like JSON, keys for undefined values are omitted when serializing objects across frames. Consider this when
    determining whether toStateObject should use null or undefined values.
  • PhET prefers to use the term "position" to refer to the physical (x,y) position of objects. This applies to both
    brands, but is more important for the PhET-iO API. See location vs position phet-info#126
  • Are your IOType state methods violating the API of the core type by accessing private fields? #287
  • When defining a boolean Property to indicate whether something is enabled with a tandem name of enabledProperty,
    use AXON/EnabledProperty. This should be done in both the model and the view. If you're using a DerivedProperty,
    skip this item.
  • Do not use translated strings in phetioDocumentaton - it changes the PhET-iO API!
@samreid samreid self-assigned this May 7, 2024
samreid added a commit to phetsims/buoyancy that referenced this issue May 7, 2024
samreid added a commit to phetsims/chipper that referenced this issue May 7, 2024
samreid added a commit that referenced this issue May 7, 2024
samreid added a commit that referenced this issue May 7, 2024
samreid added a commit that referenced this issue May 7, 2024
samreid added a commit that referenced this issue May 8, 2024
samreid added a commit that referenced this issue May 14, 2024
samreid added a commit that referenced this issue May 14, 2024
@samreid samreid changed the title Prepare for Code Review Code Review May 28, 2024
samreid added a commit that referenced this issue May 29, 2024
samreid added a commit that referenced this issue May 29, 2024
samreid added a commit that referenced this issue Jun 3, 2024
samreid added a commit that referenced this issue Jun 3, 2024
samreid added a commit that referenced this issue Jun 3, 2024
samreid added a commit that referenced this issue Jun 3, 2024
samreid added a commit that referenced this issue Jun 3, 2024
@samreid
Copy link
Member Author

samreid commented Jul 31, 2024

Code review is complete. I feel the architecture and overall setup is in good shape. I've opened side issues or TODO comments for recommendations for further improvements.

One difficulty I have in navigating the code is that it is difficult to map from the screen to the code and back. For instance, here is a panel in one of the buoyancy screens:

image

Since this is an untitled control, it is difficult to know where it lies in the files, and vice versa (looking at the files, difficult to know it is referring to that panel). I'm not sure how to solve that for this case, but it does seem to be less of a problem for the titled panels or titled accordion boxes. Just writing this down as a potential topic to keep in mind for future designs--nothing to do about it at the moment.

Of the remaining TODOs listed for this issue, some are relatively minor and can be addressed here. Others will likely want to move into a dedicated side issue. Some are questions, and some we may decide are not worth the effort. For next steps, can @AgustinVallejo and @zepumph please review the TODOs that reference this issue and take next steps?

@samreid samreid assigned zepumph and AgustinVallejo and unassigned samreid Jul 31, 2024
samreid added a commit that referenced this issue Aug 1, 2024
AgustinVallejo added a commit that referenced this issue Aug 6, 2024
@AgustinVallejo
Copy link
Contributor

We moved all the remaining TODOs into #317. Thank you very much @samreid for your thorough review!! Closing

@phet-dev
Copy link
Contributor

phet-dev commented Aug 7, 2024

Reopening because there is a TODO marked for this issue.

@AgustinVallejo
Copy link
Contributor

AgustinVallejo commented Aug 7, 2024

Reopening because there is a TODO marked for this issue.

Ironic.

Closing again

samreid added a commit to phetsims/perennial that referenced this issue Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants