Skip to content
badgerman edited this page Jan 20, 2013 · 2 revisions

No sweeping changes

As a rule, try not to change the style of files that you are not otherwise working on. Keep the diff for your changes relatively compact.

Indentation, Whitespace and Tabs

All XML files and C/C++ sources are indented by 2 spaces. Do not use tabs, and set your editor to replace with spaces. We used to indent by one tab, but that’s a long time ago, and if you see tabs, then that code is old. Feel free to replace tabs in code that you are working on.

All Lua code is indented by 4 spaces. Some of it has 2 spaces, but that is wrong. See above, fix where appropriate. Why have two differnt indentation rules for two languages? It’s historical, there’s no good reason.

Braces

Most C/C++ code looks like this:

int foo(void)
{  
  if (bar) {  
    baz();  
  } else {  
    frob();  
  }  
}

Open braces on the same line as the if/do/while/for statement, but newline for functions. else starts on the same line as the closing brace. Even one-line blocks are written as a block with braces.

Avoid trailing whitespace.

Portable C

  • Eressea compiles on a lot of platforms and compilers. There was a time it ran on the Amiga and BeOS, and it has been compiled with SGI’s compiler, lcc-win32 and tcc. Today, Linux/gcc and Windows/VC are the most commonly used targets.
  • No warnings. Eressea compiles without warnings on all supported compilers.
  • always declare no-argument functions as int foo(void), never int foo();
  • libc is our standard, not glibc. Do not use unistd.h and their ilk. Look at platform.h if you’re missing a function that isn’t in the standard.

Headers

  • include headers in alphabetical order.
  • do not include headers in other headers unless absolutely necessary
  • write header guards and #ifdef __cplusplus boilerplate
  • add the license blurb to every header

Dependencies

Dependencies go only in one direction. Avoid circles. If you feel that you'd like to break this rule, you are probably trying to solve the wrong problem.

  • Files in util/ are either standalone or depend on other files in util/.
  • Files in kernel depend on other files in kernel/ or in util/.
  • Files in gamecode depend on files in gamecode/, kernel/ or util/.

Names

All symbol names (and comments) are in English. We avoid the use of CamelCase, and use underscores to delimit words, as in add_foo_to_bar.