Tuesday, February 25, 2014

Retain or not to retain? That is the question.

When should a variable be marked retain?

  • A configuration parameter, that you want to remember the user value after a warm start.
  • A event or cycle log value, i.e., Who, What, When, Why, How.
  • An internal state value, if you want to be able to restore the program to the previous state.

When should a variable be NOT retained?

  • Values coming in from the outside every second.
  • Values going out every second. (90%)
  • Internal states, that will be reset by the warm start logic.
  • temporary variables: loop counters, intermediate results.
See the post on Cold/Warm start for code example.

No comments:

Post a Comment