Styling

The project uses clang-format to enforce a consistent coding style. There is also this code block in this website as an example of the style used in the project.

  1 // Includes
  2 #include <iostream>
  3 #include <vector>
  4 #include <string>
  5 #include <unordered_map>
  6
  7 // Constexpr over Defines
  8 constexpr int MAX_SPEED = 5 /*over #define MAX_SPEED = 5*/
  9
 10 // Constants
 11 const int SOME_NUMBER = 42;
 12 const std::string GREETING = "Hello, World!";
 13
 14 // Enums
 15 enum class Named
 16 {
 17     Thing1,
 18     Thing2,
 19     AnotherThing = -1
 20 };
 21
 22 enum class Types
 23 {
 24     PERSPECTIVE,
 25     ORTHOGRAPHIC
 26 };
 27
 28 // Example Class
 29 class MyClass
 30 {
 31     public:
 32         //Public variables
 33         int PublicNumber = 5;
 34
 35     public:
 36         // Constructor
 37         MyClass() : m_IntNumber(5), m_Name("Luigi Mangione 🫶"),
 38                     m_Numbers({1, 2, 3}), m_Dictionary({ {"key", 1} };)
 39         {
 40             // Note that there is COFFEE_INFO and COFFEE_CORE_INFO
 41             // depending on the case you should use the proper one.
 42             COFFEE_CORE_INFO("Constructed!");
 43             COFFEE_INFO("{0}, me caso", m_Name);
 44         }
 45
 46         // Example function
 47         int SomeFunction(int param1, int param2, int param3)
 48         {
 49             const int localConst = 5;
 50
 51             if (param1 < localConst)
 52             {
 53                 COFFEE_INFO("param1: {0}", param1);
 54             }
 55             else if (param2 > 5)
 56             {
 57                 COFFEE_INFO("param2: {0}", param2);
 58             }
 59             else
 60             {
 61                 COFFEE_ERROR("Fail!");
 62             }
 63
 64             for (int i = 0; i < 20; ++i)
 65             {
 66                 COFFEEINFO("Loop index: {0}", i);
 67             }
 68
 69             vector<int> v = {1, 2, 3, 4, 5};
 70             for (int i : arr)
 71             {
 72                 COFFEE_INFO("{0} ", i);
 73             }
 74
 75             while (param2 != 0)
 76             {
 77                 --param2;
 78             }
 79
 80             Types type = Types::PERSPECTIVE
 81
 82             switch (type)
 83             {
 84                 using enum Types;
 85                 case PERSPECTIVE:
 86                 {
 87                     COFFEE_INFO("type is PERSPECTIVE!");
 88                     break;
 89                 }
 90                 case ORTHOGRAPHIC:
 91                 {
 92                     COFFEE_INFO("type is ORTHOGRAPHIC!");
 93                 }
 94                 default:
 95                 {
 96                     COFFEE_INFO("type is not a type of the enum!");
 97                 }
 98             }
 99
100             return param1 + 3;
101         }
102
103         // Nested class
104         class NestedClass
105         {
106             public:
107             int nestedValue = 10;
108         };
109
110         // Function overriding
111         virtual void Something(int p1, int p2) override;
112     private:
113         // Member variables
114         int m_IntNumber;
115         std::string m_Name;
116         std::vector<int> m_Numbers;
117         std::unordered_map<std::string, int> m_Dictionary;
118 };