Tinderbox v9 Icon

Attributes vs. variables in functions

Important note: all examples follow aTbRef naming conventions.


Attributes

In a function, any attribute reference, e.g. $MyString, refers to an attribute in the calling note (i.e. the current item in a selection). It is still possible to refer to the same attribute in another note, e.g. $MyString("SomeNote").

If the function needs to store a lot of interim values, as in some string manipulation tasks, this can involve using quite a few attributes. It is no problem to create additional user attributes, even if only for this task. Note that these attributes need to be created before the function is used. Attributes can be created via the Add Displayed Attributes configuration panel (attribute name and data type only), or the Document Inspector's User tab. Only theInspector allows configuration of all aspects of a user attribute.

To minimise the build up of forgotten data consider:

Alternatively, consider action code variables, as described below

(Action code) Variables

Using action code variables within functions can help their use without needing to use any attributes, other than explicitly storing output results. Such use makes a function more self-contained, especially if planning to use the same function (or library of functions) in different Tinderbox documents. This is because the function creates/destroys variables as needed and there is no need for user attributes (see above) which might not (yet) have been created in the current document. Using variables avoids that extra set-up of configuring attributes.

Variables created within a function only work within the scope of that function, as discussed here.

Which approach is better?

…is the wrong question to ask! It is perfectly fine to use either, or a mix of both. Use whichever appeals and makes sense for the user's style of work. The choice will likely depend on a mix of personal style and the nature of use of the functions.


Next: Attributes vs. variables in functions



A Tinderbox Reference File : Objects & Concepts : Concepts : Actions : Functions : Attributes vs. variables in functions