This is not a binary, either/or question, not least because using (user) attributes to hold values during the course of an action long pre-dates the arrival of the
var
operator for variables (which was only added in v5.10.0). Data-typed variables (e.g. var:string)
arrived in v9.1.0, as did the function
operator. Data-typed function arguments, a type of variable, arrived in v9.5.0. The later version also added the ability in templates for ^value()^ to inset a variable set in an ^action()^ section further up in the template.
Thus a lot of longstanding code examples in the Tinderbox community were written before the current range of variable uses were added.
When must an attribute be used?
If the document needs to retain a value form session to session, i.e. persisting when the document is closed, that an attribute is required. This is because variables (and any value) are lost/deleted once an action is run. But, if such a value can be calculated from available information at document start, then storing a value in an attribute may be an advantage rather than a necessity.
When must a variable be used?
Never, but in all cases except that above, using a variable can make for shorter, clearer, action code. Additionally, as variable (values) are lost when an action completes, there is no need to clean up after. By comparison, passing an attribute a list of the paths of 1,000 items, so the list can then be iterated means that value remains forever unless the attribute is reset to an empty value.