Coding Style

From Mineserver Wiki
Jump to navigation Jump to search

This is a suggestion for a coding style to be used consistently accross Mineserver's source code.

  • Indentation: 2 spaces
  • Class names: PascalCase (e.g.: FurnaceManager).
  • Variable and method names: camelCase, (e.g.: updateWorld, userCommands).
    • Pointer variables: Use Foo* bar instead of Foo *bar
    • Using short names for loop variables is ok, e.g. i, j. Otherwise use descriptive names and don't use abbreviations all over the place, to make the code more readable.
  • Inline methods: Keep them short (max 10-15 lines at most).
  • Documentation: Use doxygen-style (javadoc-style?) documentation for at least all public methods. Example:
   /**
    * The foo() method. Does some fooish stuff, yo!
    * @param bar Bar instance to be used in foo().
    * @return An instance of Baz that does something fantastic!
    */
    Baz* Foo::foo(Bar* bar);
   class Foo 
   {
     public:
     Foo();
     ~Foo();
     /**
      * The foo() method. Does some fooish stuff, yo!
      * @param bar Bar instance to be used in foo().
      * @return An instance of Baz that does something fantastic!
      */
     Baz* foo(Bar* bar);
     private:
     /* private instance vars etc go here.*/
   };
   if (true)
   {
     foo = bar;
   }
   if (true)
   {
     foo = bar;
     foo2 = bar2;
   }
  • Spacing:
   Foo* bar = new Foo();
   fooBar(param1, param2, param3);
   for (int i = 0; i < 1; i++)
   {
     ...
   }