MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

Suggestion: provide string constants for all types

Open pablode opened this issue 7 months ago • 1 comments

Currently, many applications that use MaterialX repeatedly write out type strings:

const bool colorInput = (type == "color3" || type == "color4");

One problem with this is that the correct spelling of the types is not ensured by the compiler (e.g. one could by accident write float2 instead of vector2, bool instead of boolean, ..). Additionally, this paradigm does not work well with auto-completion.

Types.cpp already provides some string constants, but many others are missing: https://github.com/AcademySoftwareFoundation/MaterialX/blob/dfffe83f74e742edc3743f004da359c35cef5652/source/MaterialXCore/Types.cpp#L10-L23

Furthermore, the names are rather wordy. I believe that something short is to be preferred due to frequent use. As an example, Type String could be abbreviated and used as a prefix or namespace.

Above snippet would become:

const bool colorInput = (type == mx::TS_COLOR3 || type == mx::TS_COLOR4);

pablode avatar Jul 13 '24 10:07 pablode