Skip to content
Vlad edited this page Feb 28, 2017 · 12 revisions

Please follow those rules when writing code for Sfall.

Indentation

  • Use tabs for indentation. Recommended tab length in your editor is 4 characters.

Naming

  • Use all lowercase letters for namespace names.
  • Use PascalCase (with all capital letters) for all user-defined types (classes, structs, enums, typedefs, etc.) and non-member functions.
  • Exceptions to above rule
    • Engine function wrappers should be named exactly like original source (and most FO functions use snake_case);
    • Scripting function handlers may be called in the same style as SSL scripting function they implement (like sf_register_hook).
  • Use camelCase for variables and member functions.
  • Prefix all private/protected class members with underscore.
  • Don't use names that start with and underscore followed by an uppercase letter or names that have to adjacent underscores. Those are reserved names by the C++ standard.

Brackets

  • Place opening brackets always on the same line, except for namespace brackets.
  • Avoid writing control blocks without brackets.

Spaces

  • Always put spaces after control flow operators like if, for, while, etc.
  • Put spaces around binary operators like *, +, etc.
  • Put space after comma (,) in argument lists, etc.

Empty lines

  • Put 1 empty line between each function, class or class member declaration.

Inline ASM

  • Try to avoid writing complex ASM code (code with any condition, loop, etc.). If you want to use Engine functions, add/use Wrappers and then write all your logic in human-friendly C++ language.
  • Don't mix up code with and without semicolons at the end of lines. Be consistent.
  • Never use numeric literals for known addresses! Add/use constants.

Misc

  • Avoid writing code in C-style, like using sizeof/memset/etc when working with arrays (use std containers).
  • Use nullptr instead of NULL constant.
  • Try using std::string for strings when you need to copy, store, modify strings, etc.
  • Never use new/delete operators. Use unique_ptr to handle lifetime of objects on heap.
  • Avoid global variables, if possible. Use singleton classes or functions instead.
Clone this wiki locally