Difference between revisions of "Code style"

From PioneerWiki
Jump to: navigation, search
Line 1: Line 1:
 +
This page describes some of the code style used in Pioneer. Its probably incomplete, but it should be correct. If you see something in the code that doesn't match what's described here, this guide takes precedence (and please submit a patch to fix it!)
 +
 +
== Licensing ==
 +
 +
Engine and Lua code is [http://www.gnu.org/licenses/gpl.html GPL 3]. Assets (include Lua-based data files like ship defs) are [http://creativecommons.org/licenses/by-sa/3.0/ CC-BY-SA 3]
 +
 +
Include these two lines at the top of each file (suitably commented):
 +
 +
    Copyright © 2008-2013 Pioneer Developers. See AUTHORS.txt for details
 +
    Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
 +
 +
    Copyright © 2008-2013 Pioneer Developers. See AUTHORS.txt for details
 +
    Licensed under the terms of CC-BY-SA 3.0. See licenses/CC-BY-SA-3.0.txt
 +
 
== Tabs & spacing ==
 
== Tabs & spacing ==
  
Line 15: Line 29:
 
* Static members: s_fooBar
 
* Static members: s_fooBar
 
* Constants: FOO_BAR
 
* Constants: FOO_BAR
 +
 +
== Include guards ==
 +
 +
Header include guards should be named for the filename of the header, capitalised, with slashes converted to underscores:
 +
 +
* Ship.h
 +
    #ifndef SHIP_H
 +
 +
* WorldView.h
 +
    #ifndef WORLDVIEW_H
 +
 +
* graphics/Renderer.h
 +
    #ifndef GRAPHICS_RENDERER_H

Revision as of 02:46, 2 July 2013

This page describes some of the code style used in Pioneer. Its probably incomplete, but it should be correct. If you see something in the code that doesn't match what's described here, this guide takes precedence (and please submit a patch to fix it!)

Licensing

Engine and Lua code is GPL 3. Assets (include Lua-based data files like ship defs) are CC-BY-SA 3

Include these two lines at the top of each file (suitably commented):

   Copyright © 2008-2013 Pioneer Developers. See AUTHORS.txt for details
   Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
   Copyright © 2008-2013 Pioneer Developers. See AUTHORS.txt for details
   Licensed under the terms of CC-BY-SA 3.0. See licenses/CC-BY-SA-3.0.txt

Tabs & spacing

  • Hard tabs, 4-space aligned.
  • Inner spaces after tabs to align arguments on multiple lines, etc

Constants

  • Prefer static const over #define wherever possible

Name style

  • Classes: FooBar
  • Methods: FooBar
  • Class members: m_fooBar
  • Static members: s_fooBar
  • Constants: FOO_BAR

Include guards

Header include guards should be named for the filename of the header, capitalised, with slashes converted to underscores:

  • Ship.h
   #ifndef SHIP_H
  • WorldView.h
   #ifndef WORLDVIEW_H
  • graphics/Renderer.h
   #ifndef GRAPHICS_RENDERER_H