Coding Rules
This page describes the coding rules that are used for the development of the Tinman 3D SDK. Knowing these rules can make it easier to understand the API as well as the provided source code and examples.
Code-X
Development of the Tinman 3D SDK takes place within the scope of the Code-X Workflow, which imposes a specific set of coding rules on developers.
Knowing these rules upfront can facilitate the understanding of the included source code and examples. These rules must be followed when the Code-X Workflow is adopted for development. Otherwise, they are fully optional and may be used if it is deemed beneficial to the development process.
For details, please refer to the following documentation:
Naming Scheme
The various components of the SDK are provided as separate projects, for example in a Visual Studio solution. The names of these projects follow a simple naming scheme:
- Project.Name.CodeX
-
The .CodeX name suffix indicates that the project source code is Code-X compliant and can be fed into the Cpu-X Workflow, which produces correct source code in other CPU programming languages, such as C++.
- Project.Name.GpuX
-
The .GpuX name suffix indicates that the project source code is Code-X compliant and can be fed into the Gpu-X Workflow, which produces correct source code in other GPU programming languages, such as GLSL and HLSL.
- Project.Name.CSharp
-
The .CSharp name suffix indicates that the project source code is written in the C# programming language and is not necessarily Code-X compliant.
- Project.Name.Cpp
-
The .Cpp name suffix indicates that the project source code is written in the C++ programming language and has either been generated automatically by the Code-X Workflow or has been written manually.
Binaries for the C++ libraries of the SDK are provided as obfuscated and minimized source code, instead of static / dynamic link libraries. - Project.Name.Full.Cpp
-
The .Full.Cpp name suffix has the same meaning as the .Cpp suffix, with the exception that the contained C++ source code is not obfuscated and fully documented.
Full source code can be obtained by purchasing a Source licence.
Code Style
The following sections provide documented code examples, which explain the code style rules that defined by the Tinman 3D SDK.
The Code-X Workflow requires that all members of a type are enclosed in a region (see CxDeclarationType.Regions), but does not specify any naming rules. Only this code style defines naming rules. |
Classes / Interfaces / Structures
Classes and structures use the same code style.
class
/ struct
types/// <summary>
/// This class documents the code style guidelines of Tinman 3D.
/// </summary>
/// <remarks>
/// The following tags may be used in code comments in order to track
/// code-related issues:
/// <code>
/// TODO: ...
/// </code>
/// Depicts a task that may be done in the future, usually to add new features
/// or to improve an existing feature.
/// <code>
/// FIX: ...
/// </code>
/// Depicts a task that should be done as soon as possible, because it adds a
/// missing feature, finishes an incomplete feature or fixes a known problem.
/// <code>
/// DEBUG: ...
/// </code>
/// Indicates that the subsequent statement (which may be a block) is solely
/// used for debugging purposes and must be removed as soon as debugging is
/// done. Adhering to this rule makes it possible to strip all debug code
/// automatically.
/// <code>
/// FIX-CS: ...
/// FIX-CPP: ...
/// </code>
/// Indicates that a change has been applied to a native code block and must
/// be migrated to all Code-X translation targets. The main purpose of this is
/// to document the change itself and to create a strong reminder for
/// migration, which usually happens at some later point in time.
/// <code>
/// HACK: ...
/// </code>
/// Marks code that implements a hack-ish solution to a specific problem.
/// Although the solution is workable, it might become necessary to revise it
/// at some later point in time.
/// </remarks>
public sealed class CodeStyle : SerializableBase, IConfigurable
{
#region Configuration
/// <summary>
/// The configurator object for this type.
/// </summary>
/// <value>[not-null] The configurator object.</value>
public static IConfigurator<CodeStyle> Config
{
get { return null; }
}
public ConfigValue ToConfig()
{
return ConfigValue.Invalid;
}
#endregion
#region Serialization
/// <summary>
/// The GUID that uniquely identifies this type:
/// {40F5840E-7B30-4D93-8034-1B9323B8968D}
/// </summary>
const string SerialGuid = "40F5840E-7B30-4D93-8034-1B9323B8968D";
/// <summary>
/// Serialization information about this type.
/// </summary>
public static readonly ISerialTypeInfo SerialId =
new SerialTypeInfo<CodeStyle>("CodeStyle", SerialGuid);
#endregion
#region Public / Constants
public const int Public_Constants_1 = 1;
public static readonly object Public_Constants_2 = new object();
#endregion
#region Public / Attributes
public static int Public_Attributes_1;
public static int Public_Attributes_2
{
get { return 0; }
}
public int Public_Attributes_3;
public int Public_Attributes_4
{
get { return 0; }
}
#endregion
#region Public / Events
public event EventHandler Public_Events_1;
public event EventHandler Public_Events_2;
#endregion
#region Public / Constructors
[Factory]
public static CodeStyle Public_Constructors_1()
{
return new CodeStyle();
}
public CodeStyle()
: base(SerialId)
{
}
#endregion
#region Public / Methods
public static void Public_Methods_1()
{
}
public static void Public_Methods_2()
{
}
public void Public_Methods_3()
{
}
public void Public_Methods_4()
{
}
#endregion
#region Public / Operators
public static bool operator ==(CodeStyle a, CodeStyle b)
{
return ReferenceEquals(a, b);
}
public static bool operator !=(CodeStyle a, CodeStyle b)
{
return !(a == b);
}
public int this[int index]
{
get { return 0; }
}
#endregion
#region Protected / Constants
protected const int Protected_Constants_1 = 1;
protected static readonly object Protected_Constants_2 = new object();
protected internal const int Protected_Constants_3 = 1;
protected internal static readonly object Protected_Constants_4 =
new object();
#endregion
#region Protected / Attributes
protected static int Protected_Attributes_1;
protected static int Protected_Attributes_2
{
get { return 0; }
}
protected internal static int Protected_Attributes_3;
protected internal static int Protected_Attributes_4
{
get { return 0; }
}
protected int Protected_Attributes_5;
protected int Protected_Attributes_6
{
get { return 0; }
}
protected internal int Protected_Attributes_7;
protected internal int Protected_Attributes_8
{
get { return 0; }
}
#endregion
#region Protected / Events
protected event EventHandler Protected_Events_1;
protected event EventHandler Protected_Events_2;
protected internal event EventHandler Protected_Events_3;
protected internal event EventHandler Protected_Events_4;
#endregion
#region Protected / Constructors
[Factory]
protected static CodeStyle Protected_Constructors_1()
{
return new CodeStyle();
}
[Factory]
protected internal static CodeStyle Protected_Constructors_2()
{
return new CodeStyle();
}
protected CodeStyle(int a)
: base(SerialId)
{
}
protected internal CodeStyle(int a, int b)
: base(SerialId)
{
}
#endregion
#region Protected / Methods
protected static void Protected_Methods_1()
{
}
protected static void Protected_Methods_2()
{
}
protected internal static void Protected_Methods_5()
{
}
protected internal static void Protected_Methods_6()
{
}
protected void Protected_Methods_3()
{
}
protected void Protected_Methods_4()
{
}
protected internal void Protected_Methods_7()
{
}
protected internal void Protected_Methods_8()
{
}
#endregion
#region Private / Constants
const int Private_Constants_1 = 1;
static readonly object Private_Constants_2 = new object();
#endregion
#region Private / Attributes
static int Private_Attributes_1;
static int Private_Attributes_2
{
get { return 0; }
}
[Internal]
public static int Private_Attributes_3
{
get { return 0; }
}
int Private_Attributes_4;
int Private_Attributes_5
{
get { return 0; }
}
[Internal]
public int Private_Attributes_6
{
get { return 0; }
}
#endregion
#region Private / Events
event EventHandler Private_Events_1;
event EventHandler Private_Events_2;
#endregion
#region Private / Constructors
[Factory]
static CodeStyle Private_Constructors_1()
{
return new CodeStyle();
}
[Factory, Internal]
public static CodeStyle Private_Constructors_2()
{
return new CodeStyle();
}
CodeStyle(int a, int b, int c)
: base(SerialId)
{
}
#endregion
#region Private / Methods
static void Private_Methods_1()
{
}
static void Private_Methods_2()
{
}
[Internal]
public static void Private_Methods_3()
{
}
[Internal]
public static void Private_Methods_4()
{
}
void Private_Methods_5()
{
}
void Private_Methods_6()
{
}
[Internal]
public void Private_Methods_7()
{
}
[Internal]
public void Private_Methods_8()
{
}
#endregion
#region Logging
/// <summary>
/// The logger object of this class.
/// </summary>
public static readonly ILogger Logger = LoggingUtil.GetLogger("CodeStyle");
#endregion
}
The code style for interfaces is a simplified version of the code style for classes and structures.
interface
typespublic interface ICodeStyle
{
#region Events
event EventHandler Events_1;
event EventHandler Events_2;
#endregion
#region Attributes
int Attributes_1 { get; }
int Attributes_2 { get; }
#endregion
#region Methods
void Methods_1();
void Methods_2();
#endregion
#region Operators
int this[int value] { get; }
#endregion
}
Enumerations
If an enumeration has the FlagsAttribute, it is a flag enumeration. Otherwise, it is a regular enumeration.
If the SemanticEnumAttribute is present, then the values of the enumeration items must not change.
enum
types (regular)/// <summary>
/// This type documents the code style guidelines of Tinman 3D.
/// </summary>
/// <remarks>
/// This is a regular enumeration, which means that it does not have the
/// <see cref="FlagsAttribute"/>. For regular enumerations, the following
/// coding rules are defined:
/// <list type="number">
/// <item>
/// There must be a default enumeration item with an arbitrary name and
/// the value <c>0</c>. See <see cref="Zero"/>.
/// </item>
/// <item>
/// The values of the enumeration items should form a contiguous number
/// range. Here, this would be <see cref="Zero"/>, <see cref="One"/>,
/// <see cref="Two"/>, <see cref="Three"/>. The purpose of this is to be
/// able to iterate over all items just by looping through the number
/// range.
/// </item>
/// </list>
/// If the <see cref="SemanticEnumAttribute"/> is present, rule 2 does not
/// apply.
/// </remarks>
public enum CodeStyleEnum
{
/// <summary>
/// Default enumeration item.
/// </summary>
Zero = 0,
/// <summary>
/// Enumeration items should be documented.
/// </summary>
One = 1,
/// <summary>
/// Enumeration items should be documented.
/// </summary>
Two = 2,
/// <summary>
/// Enumeration items should be documented.
/// </summary>
Three = 3
}
The code style for flag enumerations is almost identical to the code style for regular enumerations.
enum
types (flags)/// <summary>
/// This type documents the code style guidelines of Tinman 3D.
/// </summary>
/// <remarks>
/// This is a flag enumeration, which means that it has the
/// <see cref="FlagsAttribute"/>. For flag enumerations, the following coding
/// rules are defined:
/// <list type="number">
/// <item>
/// There must be a default enumeration item with an arbitrary name (for
/// example: <c>None</c>) and the value <c>0</c>. See <see cref="None"/>.
/// </item>
/// <item>
/// The last enumeration item (for example: <c>All</c>) should contain all
/// flags that are used by the other items The purpose of this is to be
/// able to assemble flags by starting with all flags and then removing
/// specific ones, instead of starting with no flags and adding specific
/// ones.
/// </item>
/// </list>
/// If the <see cref="SemanticEnumAttribute"/> is present, rule 2 does not
/// apply.
/// </remarks>
[Flags]
public enum CodeStyleEnumFlags
{
/// <summary>
/// Default enumeration item.
/// </summary>
None = 0,
/// <summary>
/// First bit.
/// </summary>
First = 1,
/// <summary>
/// Second bit.
/// </summary>
Second = 2,
/// <summary>
/// Third bit.
/// </summary>
Third = 4,
/// <summary>
/// All bits.
/// </summary>
All = 7
}
Unit Tests
Unit test classes use the following code style.
public sealed class CodeStyleTest : TinmanTestFixture<MyTinmanModule>
{
#region Setup/Teardown
[SetUp]
public void Setup_Teardown_1()
{
}
[TearDown]
public void Setup_Teardown_2()
{
}
[OneTimeSetUp]
public static void Setup_Teardown_3()
{
}
[OneTimeTearDown]
public static void Setup_Teardown_4()
{
}
#endregion
#region Test Methods
[Test]
public void Test_Methods_1()
{
}
#endregion
#region Auxiliary Members
public int Auxiliary_Members_1;
#endregion
}