Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Code Guidelines

jbarnette edited this page · 10 revisions
Clone this wiki locally

Guidelines are guidelines, not laws. What’s important is consistency. Anybody’s welcome to change these, just get consensus and make sure all the existing code matches your new guideline.

Two spaces per indent.


// bad
if (something)
       do_something();

// good
if (something)
  do_something();

Put braces on the next line.


// bad
if (something) {
  do_something();
}

// good
if (something)
{
  do_something();
}

Don’t insert extra spaces in parentheses.


// bad
if ( (foo && bar ) || baz )
  do_something();

// good
if ((foo && bar) || baz)
  do_something();
  do_something();

Use vertical whitespace liberally.


// bad
bool do_something() {
  if (flag_p()) do_something_else();
  switch(type_of_thingy()){
  case FOO: handle_foo(); break;
  case BAR: handle_bar(); return false;
  default: handle_default();
  }
  if (flag_p()) do_something_else_again();
  return true;
}

// good
bool do_something()
{
  if (flag_p())
    do_something_else();

  switch (type_of_thingy())
  {
    case FOO:
      handle_foo();
      break;

    case BAR:
      handle_bar();
      return false;

    default:
      handle_default();
  }

  if (flag_p())
    do_something_else_again();

  return true;
}

Something went wrong with that request. Please try again.