-
-
Notifications
You must be signed in to change notification settings - Fork 9
Coding style
⚠️ WARNING: This document is largely unfinished! Please try to combine the info availalbe in here with the actual code available in the repo when making pull requests.
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.
Tabs must be used for all leftmost indentation. The width of one tab should be configured to 4 spaces in your IDE. If you'd like to add whitespace inbetween code to increase readability, always use spaces. Do not leave whitespaces on otherwise empty lines!
For all JSDoc, the required maximum line length is 80 characters! For the code itself 100 characters is fine, but try to use less and split long function calls into multiple lines.
BBMOD uses Allman style, which means braces are put onto their own lines. The only exception to this are annonymous methods, which follow the K&R style. Please note this does not apply to struct methods!
function BBMOD_SomeStruct() constructor
{
static some_method = function ()
{
// This is good
};
static some_other_method = function () {
// This is bad!!!
};
}
do_some_stuff(function () {
// This is acceptable if there isn't "too much" code in here...
});
var _callback = function () {
// Same for this one...
};
do_some_stuff(function ()
{
// No problem with this one...
});
var _callback2 = function ()
{
// Same for this one...
};
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.