wiki:CodingConventions

Even though the source code currently doesn't always follow these rules, any new code written should follow them. Old code not following the conventions will eventually get updated with the current conventions whenever it needs to be changed.

Coding Style

  • Use tabs up until the first margin, after that use spaces to have everything line up correctly with any editor settings. In this example spaces are represented by '.' and tabs by '>'.
if (x1 && x2)
{
> > DoStuff(param1, param2,
> > ........param3, param4);
}
  • Keep braces on their own line (1 line functions can skip this rule).
if (Test)
{
  x = 1;
}
else
{
  x = 2;
}
  • Add spaces before and after math operators.
int Value = x1 + x2;
  • All variables and functions should be mixed case without underscores.
  • Function arguments should have spaces after commas, but not before/after the parenthesis.
  • Function names should preferably include a verb and describe what it does.
void lcCalculateStuff(int param1, int param2);
  • Defines and enums should be uppercase and prefixed with LC_.
#define LC_EXAMPLE   1

enum
{
  LC_TYPE1
  LC_TYPE2
};
  • Prefix class member variables with m_.
  • If a struct has member functions then it should be a class.
class lcMyClass
{
public:
  void AddToValue();
  m_Value;
};

  • Any code shared by all platforms should go in the common directory, platform specific code goes into the respective platform directory.
  • Avoid using platform #ifdef's, if a function is different for each platform it should be in the platform directory.
  • Never check in code with compiler warnings or errors.
  • Source files should be all lowercase and begin with lc_.

File Conventions

  • All binary files are always written as little endian files, even on big endian computers.
  • Use the File class for reading/writing files to make sure they are endian swapped correctly.
  • Use the u32 etc types for structures that are saved to make sure they can be loaded under different platforms.
Last modified 10 years ago Last modified on Nov 2, 2006 6:29:57 PM