[Bf-committers] Coding style

Ton Roosendaal ton at blender.org
Sun Feb 20 12:14:45 CET 2005


Hi,

I've reviewed transform code, and a couple of nice style improvements  
were accepted by Martin. Thought it would be nice to mention it to list  
here as well. Below applies for most code in source/blender/, apart  
from c++ or python;

-> function naming

It helps to have a visual clue wich calls are:
- part of the exported API (for rest of Blender)
- part of the 'module' (like only for all transform files).
- entirely local (to the C function)

For Blender API functions there exist two mixed conventions now, one is  
the OpenGL style;

void glSwapBuffers()
void uiDefButton()

or as added in NaN days:

BIF_ThemeColor()
BKE_read_file()

Note that in both cases names include upper cases.
Local calls or module-only calls use lower-case, like

void ui_def_button()

and have a static declaration when strictly defined to be local to C  
function.

static void ui_def_button()

-> variable naming

Only use capitals in variable names to warn they're globals.
I also really like to see variable declarations grouped per equal  
types, and in descending size. So first structs, then floats, ints,  
shorts and ending with chars. Static or externs are on top. That's  
personaly maybe, but helps reading code :)

-> defines

Allmost all defines added since 5 years ago (when more people started  
coding blender :) have an indication which group/module/lib they belong  
to. This *especially* when exported as part of the API. Defines like  
"TRANSLATION" etc are confusing... you can do that for module-only (or  
local defines) but not for the exported ones.

Example: TRANS_xxx or TFM_xxx etc.

-> include files

Like for function names, the include files also separate in a global  
version (like BIF_interface.h) and a local version (interface.h), with  
the latter only being allowed to include for the interfacexxx.c  
function themselves.

Giving each C file its own header is in such a structure not needed,  
but can be used optionally... again, only for local exports to the  
'module' itself.

Right now, all source/blender/src/ code has the include files in  
source/blender/include. As already proposed ages ago, this src/  
directory could be modulified once. :)

-> use TABs!

Check on your editor setting!

-Ton-

------------------------------------------------------------------------ 
--
Ton Roosendaal  Blender Foundation ton at blender.org  
http://www.blender.org



More information about the Bf-committers mailing list