Webel: Mathematica: CONVENTION: Option help holders use a String variable with the prefix '$opt$', a related '$info$opt$' String, a 'def$opt$' default value expression, and optional '$warn$opt$', '$tip$opt$', '$lab$opt$', and 'type$opt$' indicator ...

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
icon_class
far fa-sticky-note
icon_class_computed
far fa-sticky-note
Note kind
Policy level
Mathematica keywords
Webel Mathematica keywords
Keywords
Dr Darren says:
This is an absolutely super tried and tested convention, and you don't need the Webel libraries to benefit from it. I use it (and without depending on the Webel libraries) in standalone Mathematica Notebook mini projects all the time.

This naming pattern for Webel option help holders for Mathematica is used throughout all Webel IT Australia coding of Mathematica libraries.

Example:

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

An additional "type" indicator (used only for documentation) may also be provided:

type$opt$doShow = (True|False);
Or using a Webel pattern helper:
type$opt$doShow = $pat$bool;
Additionally, a UML/SysML style multiplicity indicator (used only for documentation) may be provided as:
$mult$opt$doShow = "[0..1]";

The Webel utility functions are able to leverage this pattern to create ::usage documentation Strings (via the Doc` package), for the Webel Options viewers, for the Webel code-oriented HelpF` and HelpO` help registries, and in many other useful ways, such as with Tooltip info in tables, GUIs, and other displays.

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

Functions that use the an option via Options[] 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 (nice and DRY).

The '$opt$' convention is often used together with these Webel help holder conventions: There is a detailed technical slide trail describing how the Webel naming conventions for Wolfram Language code work together:

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 Webel option help holder 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)