Skip to content

CodeGuide

Joshua T. Fisher edited this page Nov 18, 2017 · 5 revisions

Code Guidelines

Below are the code guidelines that YTE uses.

General

  • Variable Declaration
    • Composition *aNewParent = composition;
    • Composition &aNewParent = composition;
  • Return Types
    • Composition* ReturnComposition();
    • Composition& ReturnComposition();
  • Tab Style
    • Spaces only, no tab characters
    • 2 space tabs
  • Namespace
    • All of the YTE engine is in the YTE namespace
  • Character Line Limit
    • Around 90 characters long
  • File headers
    • For now you can put whatever you want on the file header, later in development we will refactor our code with a chosen header style.
  • File names
    • Header files are .hpp
    • Source files are .cpp

Naming Convention

  • Macros
    • YTE[macro name]
    • Ex) YTERegister
  • Function Arguments
    • All arguments begin with 'a' to specify it is an argument.
    • Ex) function(float aName, int aName)
  • Struct or Class Member Variables
    • All members begin with 'm' to specify it is a member variable
    • Ex) float aName;
  • Template Types
    • All template types begine with 't' to specify it is a template
    • Ex) tType
  • Class, Struct, Function Casing
    • All classes are capital first letter of each word, as are function and struct names
    • Ex) ClassName, FunctionName, StructName
  • Local Variables
    • Local variables are camel case with the first being lowercase
    • Ex) localVaraible
  • Static Variables
    • Static variables are preceded by an 's'
    • Ex) sStaticVariable
  • Global Variables
    • Globals are preceded by a 'g'
    • Ex) gGlobalVariable

Organization and Branching Style

  • Braces
    • BSD Style braces only
    • EX)
if ()
{ 
  ...
}
  • Line Breaks
    • When line breaks are needed to break up long function calls, we break them on each argument.
    • The broken up arguments should all be vertically aligned, and depending on how much room there is, ideally start right next to the function all opening paren. If that is not possible, flow all arguments to one indent in on the next line.
    • We also line break on Constructor member initializer lists, the colon is indented one line in then one space, then the arguments are vertically aligned from there.
    • EX)
TypicalConstructor::TypicalConstructor(int aThis,
                                       int aHas,
                                       int aQuite,
                                       int aMany,
                                       int aArguments)
  : mThis(aThis),
    aHas(aHas),
    aQuite(aQuite),
    aMany(aMany),
    aArguments(aArguments)
{
  if (typicalCondition)
  {
    typicalVariable.TypicalMemberFunction(aThis,
                                          aHas,
                                          aLots,
                                          aOf,
                                          aArguments,
                                          aAnd,
                                          aNeeds,
                                          aBreak)
  }

  if (typicalOtherCondition)
  {
    typicalVariable.ReallyLongMemberFunctionWithManyArguments(
      aThis,
      aHas,
      aLots,
      aOf,
      aArguments,
      aAnd,
      aNeeds,
      aBreak,
      aAlsoThisHasReallyLongVariableNamesOrSubCallsWhichShouldBeBrokenUp)
  }
}

  • Include Directives
    • All include directives should be separated by their section, and alphabetized
    • We start with standard library headers, then dependencies, then YTE. Occasionally strange headers might require being first, these should require a comment if they occur.
    • Ex)
#include <vector>

#include "Bullet/btBulletDynamicsCommon.h"

#include "QtWidgets/QMainWindow.h"

#include "YTE/Core/File.hpp"

#include "YTE/Platform/File.hpp"
#include "YTE/Platform/Window.hpp"

Clone this wiki locally