-
Notifications
You must be signed in to change notification settings - Fork 84
Coding Guidelines
To make AGM's code nice and uniform, here are some standards that shall be used whenever contributing code to AGM.
2 spaces for indentation.
class Something: Or {
..class Other {
....foo = "bar";
..};
};
Tabs can be tricky sometimes, especially when it comes to sharing code with others. Additionally, a lot of people tend to forget they're using tabs when they're aligning things after the first character, which causes things to fall apart when viewing the code at different tab lengths. Only 2 spaces because class structures can get quite deep, and 4 spaces would cause the code to take the entirety of your monitor.
- opening bracket on the same line as keyword
- closing bracket in own line, same level of indentation as keyword
Yes:
class Something: Or {
class Other {
foo = "bar";
};
};
No:
class Something : Or
{
class Other
{
foo = "bar";
};
};
Also no:
class Something : Or {
class Other {
foo = "bar";
};
};
When using if
/else
, it is encouraged to put else
on the same line as the closing bracket to save space:
if (alive player) then {
player setDamage 1;
} else {
hint ":(";
};
In cases where you , e.g, have a lot of one-liner classes, it is allowed to use something like this to save space:
class One {foo = 1;};
class Two {foo = 2;};
class Three {foo = 3;};
Putting the opening bracket in it's own line wastes a lot of space, and keeping the closing bracket on the same level as the keyword makes it easier to recognize what exactly the bracket closes.
Everything that might occur in a global context should be prefixed with AGM_ and, if necessary, the containing PBO (AGM_Medical_xxx etc.). This includes stringtable entries!
Local variables should be "privatized" in most cases, to avoid unwanted namespace issues.
Whenever possible, use BIS' function system instead of manually compiling script files. This makes it easier to debug things in game and gives third-party developers an easier time using AGM functions.
All functions should include a comment at the top stating:
- Author
- Description
- Arguments with description and type
- Return Value
Some of AGM's code currently violates some of these rules. That will be fixed eventually. :>