-
-
Notifications
You must be signed in to change notification settings - Fork 9
Coding style
This document should by no means be understood as a guide for the perfect GML coding style that everyone should follow in their projects. This is simply a style that BBMOD uses, and for sake of consistency, everyone who wishes to contribute to BBMOD must use the same style.
BBMOD uses format-gml to automatically format code, so you don't need to worry about it yourself. (Please make sure to set it up though, before making PRs 🙂) In short, we're using Allman style with tabs for indentation (size 4) and 120 characters line length.
Naming in BBMOD coding style is quite complicated. It has evolved in early days of GameMaker, when the syntax highlight and code completion was not really good. There are different naming convetions for different things to be able to tell their type and/or scope.
Local variables use camelCase
and are prefixed with a single underscore _
, e.g. _myLocalVariable
. The exception to this rule are local variables used as counters in loops, e.g. i
, j
, k
, etc.
Global variables use camelCase
and bbmod
prefix, e.g. global.bbmodGlobalVariable
. To express that a global variable is private, use double underscore prefix, e.g. global.__bbmodPrivateGlobalVariable
.
Object variables use camelCase
. To express that an object variable is private, use double underscore prefix, e.g. __privateVariable
.
Functions use snake_case
with bbmod_
prefix, e.g. bbmod_do_some_stuff
. To express that a function is private, use double underscore prefix, e.g. __bbmod_do_some_private_stuff
.
Macros are UPPERCASE_WITH_UNDERSCORES
with BBMOD_
prefix, e.g. BBMOD_MY_MACRO
. To express that a macro is private, use double underscore prefix, e.g. __BBMOD_MY_PRIVATE_MACRO
.
Structs use UpperCamelCase
with BBMOD_
prefix, e.g. BBMOD_RenderQueue
. To express that a struct is private, use double underscore prefix, e.g. __BBMOD_PrivateStruct
.
Struct variables use UpperCamelCase
. Private struct variables follow the same naming style as private instance variables, i.e. __privateStructVariable
!
Same as functions, struct methods also use snake_case
and double underscore prefix to express that the method is private.
Unfortunately, there are a few structs that don't follow this rule (e.g. use UpperCamelCase
names instead). When adding new methods to such struct, use the same naming style that they use, but when adding new structs, please stick to the snake_case
naming!
Enums use UpperCamelCase
and BBMOD_E
prefix, e.g. BBMOD_EMyEnum
. To express that an enum is private, use double underscore prefix, e.g. __BBMOD_EMyPrivateEnum
. Enum members also use UpperCamelCase
, with an exception of SIZE
, which can be used as the last member of an enum to store the total number of members of the enum, e.g.:
enum BBMOD_EMyEnum
{
First = 0,
Second,
Third,
SIZE,
};
If a script contains a definition of a single struct or a single function, us the same name for the script itself. For other script that contain multiple definitions, use snake_case
with __bbmod_
prefix, e.g. __bbmod_array_utils
.
Resources except for scripts use prefix BBMOD_
, followed by the resource type prefix and then the resource name in UpperCamelCase
, e.g. BBMOD_RmMain
, BBMOD_OPlayer
etc. To express that a resource is private, use double underscore prefix, e.g. __BBMOD_SprMyPrivateSprite
.
Resource type | Prefix |
---|---|
Animation curve | Ac |
Font | Fnt |
Object | O |
Particle system | Ps |
Path | Pth |
Room | Rm |
Sequence | Sq |
Shader | Sh |
Sound | Snd |
Sprite | Spr |
Tile set | Ts |
Timeline | Tl |
BBMOD structs use fluent API, which means that if a struct method does not have a return value, it returns self
so you could chain multiple methods together.