Webel Best Practice: Mathematica: Options are encapsulated as a String variable with the prefix '$opt', and have a related '$info$opt$' String (help), '$lab$opt' String (label), a 'def$opt' default value expression, and an optional '$warn$opt' String.

Webel IT Australia promotes the amazing Mathematica tool and the powerful Wolfram Language and offers professional Mathematica services for computational computing and data analysis. Our Mathematica tips, issue tracking, and wishlist is offered here most constructively to help improve the tool and language and support the Mathematica user community.
DISCLAIMER: Wolfram Research does not officially endorse analysis by Webel IT Australia.
Icon class
far fa-sticky-note
far fa-sticky-note
Note kind
Policy level

This naming pattern for options to functions in Mathematica is used throughout all Webel IT Australia coding of Mathematica libraries.


$opt$doShow = "doShow";
$info$opt$doShow = "Whether to show something.";
$lab$opt$doShow = "Show?";
def$opt$doShow = True;
$warn$opt$doShow = "Setting this True may make the display much larger.";

Utility functions are able to leverage this pattern to create option registries, and to display options in flexible and powerful ways, such as with Tooltip info in tables and other displays.

This naming pattern works well for prompting in Mathematica notebooks and in Wolfram Workbench (so much less typing of Strings).

This naming pattern makes tracking usages of options across Mathematica code libraries and Packages/Paclets massively easier!

Functions that use an option may choose to leverage the 'def$opt$' default for the particular option or override it.

The use of the 'def$opt$' default for an option makes it easier to change the policy for the default across a project.

If you are a fan of object-orientation (and have understood it CAN be used together with functional programming), you might be wondering why the policy isn't encapsulated as a class. Mathematica does not yet have vendor supported OO. The option naming pattern shown can indeed be used with the user contributed MTools package for OO in Mathematica, but is also designed to work with regular Wolfram Language usage.

Relates to
Related notes
Related notes (backlinks)
Related snippets (extracts)
Visit also
Visit also (backlinks)