Coding Style
OpenCatapult uses EditorConfig to help developers adhere with consistence coding style.
For usage in Visual Studio 2017, you can find the guide in this article.
If you work with Visual Studio Code, you can use this plugin. There are various plugins available for many IDE of your choice, which you can find the list in the EditorConfig website.

Naming Guidelines

    Do use PascalCasing for class names and method names
1
public class ClientActivity
2
{
3
public void ClearStatistics() {}
4
public void CalculateStatistics() {}
5
}
Copied!
    Do use camelCasing for method arguments and local variables
1
public class UserLog
2
{
3
public void Add(LogEvent logEvent)
4
{
5
int itemCount = logEvent.Items.Count;
6
// ...
7
}
8
}
Copied!
    Do NOT use Hungarian notation or any other type identification in identifiers
1
// Correct
2
int counter;
3
string name;
4
5
// Avoid
6
int iCounter;
7
string strName;
Copied!
    Do NOT use Screaming Caps for constants or readonly variable
1
// Correct
2
public static const string ShippingType = "DropShip";
3
4
// Avoid
5
public static const string SHIPPINGTYPE = "DropShip";
Copied!
    Do NOT use Underscores in identifiers. Exception: you can prefix private variables
    with an underscore.
1
// Correct
2
public DateTime clientAppointment;
3
public TimeSpan timeLeft;
4
5
// Avoid
6
public DateTime client_Appointment;
7
public TimeSpan time_Left;
8
9
// Exception
10
private DateTime _registrationDate;
Copied!
    Do use predefined type names instead of system type names like Int16, Single, UInt64, etc
1
// Correct
2
string firstName;
3
int lastIndex;
4
bool isSaved;
5
6
// Avoid
7
String firstName;
8
Int32 lastIndex;
9
Boolean isSaved;
Copied!
    Do use implicit type var for local variable declarations. Exception: primitive types (int, string, double, etc) use predefined names.
1
var stream = File.Create(path);
2
var customers = new Dictionary();
3
4
// Exceptions
5
int index = 100;
6
string timeSheet;
7
bool isCompleted;
Copied!
    Do use noun or noun phrases to name a class.
1
public class Employee {}
2
public class BusinessLocation {}
3
public class DocumentCollection {}
Copied!
    Do prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives.
1
public interface IShape {}
2
public interface IShapeCollection {}
3
public interface IGroupable {}
Copied!
    Do name source files according to their main classes. Exception: file names with partial classes reflect their source or purpose, e.g. designer, generated, etc.
1
// Located in Task.cs
2
public partial class Task {}
3
4
// Located in Task.generated.cs
5
public partial class Task {}
Copied!

Layout Conventions

    Do write only one statement per line
    Do write only one declaration per line
    Do add at least one blank line between method definitions and property definitions
    Do use parentheses to make clauses in an expression apparent, as shown in the following code:
1
if ((val1 > val2) && (val1 > val3))
2
{
3
// Take appropriate action.
4
}
Copied!

Type Design Guidelines

Abstract Class

    Do NOT define public or protected internal constructors in abstract types.
Constructors should be public only if users will need to create instances of the type. Because you cannot create instances of an abstract type, an abstract type with a public constructor is incorrectly designed and misleading to the users.
    DO define a protected or an internal constructor in abstract classes.
    DO provide at least one concrete type that inherits from each abstract class that you ship.

Static CLass

    DO use static classes sparingly.
Static classes should be used only as supporting classes for the object-oriented core of the framework.
    Do NOT treat static classes as a miscellaneous bucket.
    Do NOT declare or override instance members in static classes.

Interface

    AVOID using marker interfaces (interfaces with no members)
    DO provide at least one type that is an implementation of an interface
    DO provide at least one API that consumes each interface you define (a method taking the interface as a parameter or a property typed as the interface)

References

Last modified 3yr ago