We have a couple of DNA types that are wrapped with C++ types improving code ergonomics. The issue is that the correlation between the DNA and wrapper type name is not standardized and can sometimes be confusing. This document proposes a simple naming scheme to solve this.
This was also discussed a bit in a recent admins meeting but without a clear result yet, so any feedback is welcome.
Existing Examples
Here are a few examples of wrapped types that we used in Blender already. Generally, the DNA type has a wrap()
method that casts it to the corresponding wrapper type.
DNA Name | Wrapper Name |
---|---|
::CurvesGeometry |
blender::bke::CurvesGeometry |
::GreasePencilLayer |
blender::bke::greasepencil::Layer |
::ActionSlot |
blender::animrig::Slot |
There are two main cases currently:
- The DNA and wrapper types have the same name but they are in different namespaces. In this case it’s more obvious that they are the same, but whenever the type name is used, it’s very context dependend what type is meant. For example, if
CurvesGeometry
is used in theblender::bke
namespace, it refers to the wrapper type, but if it is used inblender::nodes
it refers to the DNA type. This is especially confusing to people getting into a new area in Blender, because it’s a problem that usually does not exist. - The DNA and wrapper type have very different names making the relation between them less obvious.
Proposal
The proposed naming scheme is fairly straight forward: Use the same name for both types except that the DNA type has a “DNA” suffix.
The suffix is added on the DNA types instead of the wrapper types, because the wrapper types are expected to be used way more often. The DNA types are generally only used for file reading and writing.
We’d use DNA_STRUCT_RENAME
to make sure that this has no impact on file compatibility.
The examples above would be changed as follows.
DNA Name | Wrapper Name |
---|---|
::CurvesGeometryDNA |
blender::bke::CurvesGeometry |
::GreasePencilLayerDNA |
blender::bke::greasepencil::GreasePencilLayer |
::ActionSlotDNA |
blender::animrig::ActionSlot |
Discussion
This solves the two mentioned problems:
- The types never have exactly the same name anymore, so it’s never ambiguous which of these types we refer to. For example,
CurvesGeometry
always refers to the wrapper type whereasCurvesGeometryDNA
always refers to the DNA type. - The types have very similar names, making it obvious that they relate to each other.
The main downside is that the new wrapper names are a bit more verbose (Layer
vs. GreasePencilLayer
). Personally, I feel like this kind of verbosity is fine since it seems to result in more obvious local code.
Names like Layer
and Slot
are very common and while it’s nice to use such short names, they are also context dependend. By that I mean that you have to be aware of what context/namespace you are in. They are also not very searchable.
We could consider to add all of these wrapper types to the global or blender::
namespace to avoid the redundancy when refering to them from other namespaces. The DNA types are in global namespace already anyway. However, that can also be considered separately.