β Back to Home
In this Article:
π€ Notice something is missing or not working? β Please contact Zoel (zoelbastianbach@agate.id) on Ms. Teams!
https://embed.notionlytics.com/s/VjIxdGJWWmtiRzAzU1c1VVVsbERZMFJ1TURFPQ==
Consistency is the key to maintainable code. This statement is most true for naming your projects, source files, and identifiers including Fields, Variables, Properties, Methods, Parameters, Classes, Interfaces, and Namespaces.
The table below is the summary/TL;DR version of the naming conventions in this article:
β ALWAYS use camelCase or PascalCase names
β AVOID the use of ALL CAPS and all lowercase names. Single lowercase words or letters are acceptable.
β DO NOT create declarations of the same type (namespace, class, method, property, field, or parameter) and access modifier (protected, public, private, internal) that vary only by capitalization. Assume you will be working with languages that does not support case-sensitivity, even if you know you're not.
public int SomeIntVariable;
public int SomeintVariable;
public int SomeIntvariable;
β DO NOT use names that begin with a numeric character.
// **β** DO NOT do this:
public class 6AxisControler {}
// **β
** DO this instead:
public class SixAxisControler {}
β ALWAYS choose meaningful, self-explanation and specific names
// **β** DO NOT do this:
public int Asdf;
//a = final position
//b = current position
//c = pivot
a = b β c;
// **β
** DO this instead:
public int BallCount;
finalPos = currentPos β pivot;
Variables and Properties should describe an entity not the type or size. And also do not use Hungarian Notation
// **β** DO NOT do this:
public int nBall; //number of ball
public bool bBusy; //Boolean variable
// **β
** DO this instead:
public int BallCount;
public bool IsBusy;
β AVOID using abbreviations unless the full name is excessive (more than 25 character).
// **β** DO NOT do this:
public float ExtGlow;
public int GetTheLatestWebSiteAccessTimeInMilliseconds()
// **β
** DO this instead:
public float ExternalGlow;
public int GetLatestWebAccessTimeMillis()
Any Abbreviations must be widely known and accepted.
public int Atk;
public int Def;
public float Pow;
β DO NOT use C# reserved words as names.
β AVOID naming conflicts with existing .NET Framework namespaces, or types.
β AVOID adding redundant or meaningless prefixes and suffixes to identifiers
// **β** DO NOT do this:
public enum ColorsEnum
public class CVehicle
public struct RectangleStruct
// **β
** DO this instead:
public enum Colors
public class Vehicle
public struct Rectangle
β DO NOT include the parent class name within a property name.
// **β** DO NOT do this:
public class Customer {
public int CustomerName;
}
// **β
** DO this instead:
public class Customer {
public int Name;
}
β TRY to prefix boolean variables and properties with βCanβ, βIsβ or βHasβ.
Append computational qualifiers to variable names like Average, Count, Sum, Min, and Max where appropriate.
When defining a root namespace, use a Product, Company, or Developer Name as the root.
Agate.ProductName
Capitalization: PascalCase
β ALWAYS match class name and file name.
β AVOID including more than one class, enum (global), or delegate (global) per file.
Use a descriptive file name when containing multiple class, enum (global), or delegate (global).
MyClass.cs
public class MyClass {β¦}
Capitalization: PascalCase
Use a noun or noun phrase for class name. Add an appropriate class-suffix when sub-classing another type when possible.
private class MyClass {β¦}
internal class SpecializedAttribute : Attribute {β¦}
public class CustomerCollection : CollectionBase {β¦}
public class CustomEventArgs : EventArgs {β¦}
private struct GameSettings {β¦}
Capitalization: PascalCase
β ALWAYS prefix interface name with capital βIβ
interface ICreature {β¦}
interface IWeapon
Capitalization: PascalCase
β ALWAYS use a single capital letter, such as T or K.
public class FifoStack<T> {
public void Push(T obj) {β¦}
public T Pop() {β¦}
}
Capitalization: PascalCase
β TRY to use a Verb or Verb-Object pair.
public void Execute() {β¦}
private string GetAssemblyVersion(Assembly target) {β¦}
Capitalization: PascalCase
Property name should represent the entity it returns. Never prefix property names with βGetβ or βSetβ.
// DO NOT do this:
public string GetName {
get{β¦}
}
// DO this instead:
public string Name {
get{β¦}
set{β¦}
}
Capitalization: PascalCase
β AVOID using non-private Fields! Use Properties instead.
public string Name;
protected IList InnerList;
Capitalization: camelCase
Prefix with a single underscore ( _ ) character.
private string _name;
Treat like a Field. Choose appropriate Field access-modifier above.
Capitalization: PascalCase (both the Type and the Options).
Add the FlagsAttribute to bit-mask multiple options.
public enum CustomerTypes
{
Consumer,
Commercial
}
Treat as a Field. Choose appropriate Field access-modifier above.
public event EventHandler LoadPlugin;