BlenderDev/Blender2.5/NamingConvention
From BlenderWiki
Contents |
[edit] Function name conventions
A function should be named with subject first, then the verb:
<prefix>_<what it is>_<what it does>
Prefix is the "module", and can be upper or lower case, if it's upper case, means exported outside its own module (the API), with lower case it's a local module only, for example:
void WM_screen_activate()
void wm_check()
If a function is only used inside a C file, it should be made static. It then doesn't have to follow the prefix rule, depending on clarity...
static void wm_window_close()
static int query_qual()
[edit] Struct name conventions
The same prefix and order rule can apply to exported struct names, but with the openGL convention, to have them clearly distinguished from function names. for example:
struct wmWindowManager {
};
struct uiBlock {
};
Structs on global (kernel) level can get a 'b' prefix:
struct bContext {
};
But that's not enforced really... (see DNA structs)
[edit] #define name conventions
Defines are always fully capitalized, and have prefix to show origin:
WM_NOTE_WINDOW_REDRAW
to prevent prefixes to become confusingly long, special ones are fine too, like for keymap defines:
KM_ALT
KM_PRESS
[edit] Operator definitions
For Operator definitions it's important to find out where they are located. Here an extra OT is added in the name, to indicate "Operator Type"
WM_OT_window_duplicate
ED_SCR_OT_cursor_type
ED_UI_OT_button_activate
Since these are names saved in operator stacks (macros) it's important to make them nice and future proof.
[edit] Variables
- Variable names are lower case only, also in structs
- Names are minimal 2 characters, unless it's a counter in a loop.
[edit] Code Layout
Preferred usage of {} and () and spaces/newlines:
void function(int *v1, int *v2)
{
int *v3= v1;
/* initialize */
if (v1)
something(v1);
else if (v2) {
something_else(v2);
}
else if (v3 || v1) {
something_else(v3);
}
/* now do something different */
function_different(v1, v2);
}
