C4Script Style Guidelines: Difference between revisions
No edit summary |
|||
Line 48: | Line 48: | ||
Naming prefixes for IDs: | Naming prefixes for IDs: | ||
* for libraries and GUI elements: <code>Library_*</code>, <code>GUI_*</code> | * for libraries, icons and GUI elements: <code>Library_*</code>, <code>Icon_*</code>, <code>GUI_*</code> | ||
* for goals, rules and environment objects: <code>Goal_*</code>, <code>Rule_*</code>, <code>Environment_*</code> | * for goals, rules and environment objects: <code>Goal_*</code>, <code>Rule_*</code>, <code>Environment_*</code> | ||
* for spells: <code>Magic_</code> | * for spells: <code>Magic_</code> | ||
* prefixes for scenario-local objects and addon-packs | * prefixes for scenario-local objects and addon-packs |
Revision as of 15:15, 2 March 2010
Since many people are involved in the project, it is necessary to define some styling guidelines so that other developers can read your code more easily. Please adhere to this example if you edit or add new scripts:
Example
/*-- Object title Author: Author(s) Description, including implementation details that might be interesting for other scripters --*/ local some_variable; // Explanation of what the function does public func DoSomething() { var foo = 1; // implementation commentars if (foo == DIR_Left) { some_variable++; CreateObject(:Goal_Melee); } if (foo && some_variable) foo = foo + 1; return foo; }
In words
Naming conventions:
- generally, use meaningful identifiers which are self explanatory: e.g.
weapon_strength
rather thaniStr
- don't use hungarian notation, preferably use
lowercase_separated_by_underscores
- use
CamelCase()
for functions - use
PREFIX_Identifier
for static constants
Indents, braces and spaces:
- indent code with one tab
- use the braces on own lines on the same indent level as the control structure / function declaration
{...}
braces are not required for single line statements but can be added if it improves readability- use spaces between operators like +, -, *, /, &&, || etc.
Comments:
- especially for library objects or objects with an interface used by other objects, write an introductory comment including title, author(s) and a description
- please comment your script where it is necessary for other scripters to understand what you've done
Naming prefixes for IDs:
- for libraries, icons and GUI elements:
Library_*
,Icon_*
,GUI_*
- for goals, rules and environment objects:
Goal_*
,Rule_*
,Environment_*
- for spells:
Magic_
- prefixes for scenario-local objects and addon-packs