4.3 Notes on dynamics

Useful notes taken from different places from Mathematica documentation. And some added by me.

  1. (added 7/5/14) There is a race condition between when updating a variable in the second argument of dynamics, which is also updated in the Manipulate expression. The problem is easy to explain

    Manipulate[.... n=n+1;...., Manipulator[Dynamic[f,{f=#;n=0}&....]

    Now, what happens, sometimes, is that when moving the slider, and setting \(n=0\), that this update to \(n\) can be lost, since it depends on the timing of when this happens. The Manipulate expression could be in the middle on updating \(n\) itself. This is classical lost update problem in multi-threading. The way to avoid this, is to follow this rule of thumb: When using second argument of dynamics in a Manipulate control, do not update a shared variable which can also be updated inside the Manipulate expression, as the update can be lost. The write to the shared variable/updating should only happen either inside the Manipulate expression or in the second argument of dynamics. But not in both places

  2. Dynamic is wrapped around the whole expression, so evaluation of the Table command is delayed until the output is displayed in the notebook. Any time the value of x is changed, the Table command will be reevaluated.
  3. Remember that Dynamic has the effect of delaying evaluation until the expression reaches the front end
  4. Because it has the attribute HoldFirst, Dynamic does not evaluate its first argument. This is fundamental to the workings of Dynamic, but it can lead to a somewhat unexpected behavior
  5. Ordinary variables in Mathematica are owned by the kernel. Their values reside in the kernel, and when you ask Mathematica to display the value in the front end, a transaction is initiated with the kernel to retrieve the value.
  6. Variables declared with DynamicModule, on the other hand, are owned by the front end. Their values reside in the front end, and when the front end needs a value, it can be retrieved locally with very little overhead.
  7. The most important is the fact that values of all DynamicModule variables are saved in the file when the notebook is saved.
  8. By default, dynamic outputs triggered by changes in variable values are updated no faster than twenty times per second (this rate can be changed with the SystemOption  "DynamicUpdateInterval").
  9. Dynamic outputs are only updated when they are visible on screen.
  10. Remember to add synchorization->False to all dynamics, else will time out. When using Refresh also.
  11. Never make a refresh[] tracks on 2 of my own symbols (not control variables). Use tick, only. Causes major synchronization problems with I update 2 variables inside a refresh, and have the refresh tracks both. Only make one track local variable, such as ticks
  12. Ok, Found out that finishDynamic[] can causes annoying refresh on the UI whenever I move sliders. So removed it.
  13. Remember to use :> and not -> for TrackedSymbols