Coding Standards in C++

Increasingly, our projects and teams span more programming languages.

The coding standards for C++ presented below are designed specifically for consistency with these existing Coding Standards in C#.

Coding Templates

One coding template example is below and the rest are available on GitHub.

/**
 *   CONTRIBUTORS:
 *   Sam Rivello - sam@UnityGameDeveloper.com
 *   -------------------------------------------------------------------------------------------------
 */

#ifndef TemplateClass_hpp
#define TemplateClass_hpp
#include <iostream>
using namespace std;

namespace RMC { namespace Core { namespace Templates
{
    
    class TemplateClass
    {
        private:
        
        //  Fields -------------------------------------------------------------------------------
        string _samplePrivateText;
            
        public:
        
        //  Initialization -----------------------------------------------------------------------
        TemplateClass(void);
    
        //  Methods ------------------------------------------------------------------------------
        string SamplePublicMethod (string message);
    
        //  Event Handlers -----------------------------------------------------------------------
        void Target_OnEventOccurred (void);
    };
}}}

#endif
/**
 *   CONTRIBUTORS:
 *   Sam Rivello - sam@UnityGameDeveloper.com
 *   -------------------------------------------------------------------------------------------------
 */

#include "TemplateClass.hpp"

namespace RMC { namespace Core { namespace Templates
{
    //  Fields ---------------------------------------------------------------------------------------
    string _samplePrivateText;
    
    //  Properties -----------------------------------------------------------------------------------
    string SamplePublicText() { return _samplePrivateText; }
    void SamplePublicText(string v) { _samplePrivateText = v; }
    
    //  Initialization -------------------------------------------------------------------------------
    TemplateClass::TemplateClass (void)
    {
        
    }
    
    //  Methods --------------------------------------------------------------------------------------
    string SamplePublicMethod (string message)
    {
        return message;
    }
    
    //  Event Handlers -------------------------------------------------------------------------------
    void Target_OnEventOccurred ()
    {
        
    }
}}}

Coding Standards in C#

Unity3D is a powerful suite of tools (Project IDE, Code IDE, and run-time) for game development. Unity supports several languages, but the community consensus is to use only C#. Having good coding standards and an established project structure is beneficial to your project and your team.

Pros

Regardless of which convention you choose to use for Unity or other platforms, having some sort of convention is considered a good idea by the majority of the development community.

  • Consistency – The code base as consistency in presentation regardless of team location, spoken language, or individual programmers .
  • Integration – The code, the review of the code, and your team are more tightly integrated. Theoretically, the code is more interoperable (copy/paste) and mutually intelligible.
  • Communication – Developers more implicitly understand each other in written and verbal communication.

Cons

Few developers argue the benefits of coding conventions, yet many argue if the time and discipline required is worth it.  More contentious yet — what are the criteria of a good standard? A few criteria most people can agree on are here.

  • Consistency – Whatever rules there are should be applied evenly and applied everywhere.
  • Pragmatism – The convention should be concerned with ‘important’ things and nothing else.

Next Steps

Read my complete article on coding standards…