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

Shall we add an item to the code review that forbids setTimeout and setInterval? #59

Closed
samreid opened this issue Sep 20, 2017 · 19 comments

Comments

@samreid
Copy link
Member

samreid commented Sep 20, 2017

In phetsims/energy-skate-park-basics#380 (comment) @jonathanolson said:

Please don't use setTimeout, for the reasons it is banned from usage by our code review guidelines.

Should we add entries to the code review checklist forbidding setTimeout and setInterval?

@samreid
Copy link
Member Author

samreid commented Sep 20, 2017

We could catch these even more eagerly if we forbid them with lint rules.

@pixelzoom
Copy link
Contributor

I'd prefer a lint rule to yet-another checklist item.

@zepumph
Copy link
Member

zepumph commented Sep 22, 2017

I wonder what is best here. I see many setTimeout calls in places that seem fine to me. In aqua, the sonification wrappers, yotta. We use the same lint rules to lint those repos as we do sim code.

Please don't use setTimeout, for the reasons it is banned from usage by our code review guidelines.

I wonder if @jonathanolson can speak to what these "reasons" are. I see tons of usages in joist, as well as implementations in some Timer types in common code. I think it warrants discussion before a blanket lint rule is implemented that isn't helpful because it creates too many false negatives.

@jonathanolson
Copy link
Contributor

I wonder if @jonathanolson can speak to what these "reasons" are. I see tons of usages in joist, as well as implementations in some Timer types in common code. I think it warrants discussion before a blanket lint rule is implemented that isn't helpful because it creates too many false negatives.

The reasons are that if window.setTimeout or window.setInterval are used, then generally it means the sim can't accurately be used to play back event streams in an identical fashion, since it depends on external timing (the setTimeout/setInterval will potentially execute at a different time, particularly if it shouldn't have been executed at all, e.g. if a sim is paused).

In aqua/yotta (and potentially the sonification wrappers), it isn't in the sim, so it wouldn't affect playback.

@zepumph
Copy link
Member

zepumph commented Oct 2, 2017

Makes sense thanks. I'm in favor of adding this item to the checklist, or somehow branching some eslint code into a Sim only and all lint rules.

@samreid
Copy link
Member Author

samreid commented Oct 2, 2017

If there aren't too many occurrences outside of sim code, those cases could use // eslint-disable directives.

@zepumph
Copy link
Member

zepumph commented Oct 3, 2017

I think we should explore a lint rule.

@pixelzoom
Copy link
Contributor

There is already an item in the CRC. It was added by @samreid on 12/1/17. The commit message does not indicate that it was added to address this issue.

  • All dynamics should be called from Sim.step(dt), do not use window.setTimeout or window.setInterval. This will help support Legends of Learning and PhET-iO.

Adding these to bad-text.js lint rule seems problematic, since we may use those tokens elsewhere.

@pixelzoom
Copy link
Contributor

Having a code-review item seems to have been sufficient for the past 2 years, so I propose that we close this issue and take no further action on the lint rule.

@zepumph
Copy link
Member

zepumph commented Oct 1, 2019

I agree, but also thought I'd mention that there is bad text for only sims if you want to investigate adding them there.

I'm a proponent of more list rules and less checklist items. This is both for Devs that have been here for ages, but also in helping the onboarding process.

@pixelzoom
Copy link
Contributor

pixelzoom commented Oct 1, 2019

I agree that lint rules are preferred in general. But I do not think that they are always worth the cost in practice, or in this specific case.

@pixelzoom
Copy link
Contributor

pixelzoom commented Oct 3, 2019

10/3/19 dev meeting:

@zepumph is going to check for these in bad-text.js:

window.setTimeout
setTimeout
window.setInterval
setInterval

@zepumph
Copy link
Member

zepumph commented Oct 3, 2019

See also phetsims/chipper#737 if a regex is easier (I don't think it will be).

jbphet added a commit to phetsims/area-builder that referenced this issue Nov 8, 2019
@jbphet
Copy link
Contributor

jbphet commented Nov 8, 2019

Fixed in Area Builder, checked above. Unassigning myself.

@jbphet jbphet removed their assignment Nov 8, 2019
samreid added a commit to phetsims/circuit-construction-kit-common that referenced this issue Nov 11, 2019
samreid added a commit to phetsims/scenery-phet that referenced this issue Nov 11, 2019
samreid added a commit to phetsims/circuit-construction-kit-black-box-study that referenced this issue Nov 11, 2019
@samreid samreid removed their assignment Nov 11, 2019
@samreid
Copy link
Member Author

samreid commented Nov 11, 2019

I'm all set, thanks @zepumph. Over to you @jonathanolson

jonathanolson added a commit to phetsims/collision-lab that referenced this issue Mar 18, 2021
@jonathanolson
Copy link
Contributor

Apologies about the delay! Handled the above cases.

A few have come up, and I'm not confident in handling them myself:

/Users/jon/phet/git/john-travoltage/js/john-travoltage/view/vibrationController.js
  111:1  error  Line contains bad text: 'setTimeout('  bad-sim-text
  114:1  error  Line contains bad text: 'setTimeout('  bad-sim-text

/Users/jon/phet/git/scenery/js/accessibility/speaker/webSpeaker.js
  210:1  error  Line contains bad text: 'setTimeout('  bad-sim-text

/Users/jon/phet/git/tappi/js/view/SelfVoicingLandingDialog.js
  103:1  error  Line contains bad text: 'setTimeout('  bad-sim-text

@jessegreenberg are you familiar with these cases?

@jessegreenberg
Copy link
Contributor

Thanks, these were easy to convert to stepTimer. These were the last ones so I added what was commented out in bad-sim-text in phetsims/chipper@56e2504. @samreid @zepumph is there anything else to do for this issue?

@zepumph
Copy link
Member

zepumph commented Mar 19, 2021

Very exciting! Thanks

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

7 participants