Version: Jul 10, 2026
Coding Standards
Organizing code in a consistent and predictable way improves code readability, maintainability, and reduces merge conflicts. Follow these general best practices across all programming languages:
- Use clear and descriptive naming conventions for variables, methods, and classes.
- Write meaningful comments to explain complex logic or important decisions.
- Handle errors gracefully with appropriate error handling and logging.
- Keep functions and methods focused on a single responsibility.
- Maintain consistent indentation and formatting throughout the codebase.
Adhering to these principles lays a solid foundation for writing clean, maintainable, and understandable code.
Take a look at the bottom of the page to see a 'live' example.
Table of Contents
C# Coding Standards
Organizing class members in a consistent and predictable order improves code readability, maintainability, and reduces merge conflicts. According to StyleCop's official rules, here's the recommended ordering for elements inside a class, struct, or interface.
LINQ usage
- Use query syntax for readability in complex queries.
- Use method syntax (.Select, .Where) for short inline logic.
- Async/await
- Always use Async suffix in method names.
- Avoid async void except for event handlers.
Async/await
- Always use Async suffix in method names.
- Avoid async void except for event handlers.
Handling Exceptions to the Rule
Sometimes you’ll want to group related members (like interface implementations) together, even if it breaks the standard order.
Best practice: use partial classes to separate those concerns cleanly.
public partial class MyClass {
}
public partial class MyClass : IMyInterface {
}
Example Class Layout
public abstract class BaseClass
{
public abstract void AbstractOperation();
public virtual void VirtualOperation()
{
Console.WriteLine("BaseClass: Default virtual operation");
}
}
public class SampleClass : BaseClass
{
public const string APP_NAME = "MyApp";
private readonly int _id;
private string _name;
public SampleClass(int id, string name)
{
_id = id;
_name = name;
}
public int Id => _id;
public string Name
{
get => _name;
set => _name = value;
}
public override void AbstractOperation()
{
Console.WriteLine("SampleClass: Implementation of abstract operation");
}
public override void VirtualOperation()
{
Console.WriteLine("SampleClass: Overridden virtual operation");
}
public void DisplayInfo()
{
Console.WriteLine($"ID: {_id}, Name: {_name}");
}
protected void ResetName()
{
_name = string.Empty;
}
private void LogChange(string oldName, string newName)
{
Console.WriteLine($"Name changed from {oldName} to {newName}");
}
}
Swift Coding Standards
Swift-specific coding standards and best practices will be added here to guide clean and maintainable Swift code development.
Naming Conventions
- Use PascalCase for types (classes, structs, enums, protocols).
- Use camelCase for properties, variables, and functions.
Optionals Handling
- Prefer
guard let or if let to safely unwrap optionals.
- Avoid force unwrapping (
!) unless absolutely sure the value is non-nil.
File Organization Order
- Imports
- Typealiases
- Structs and Classes
- Extensions
Example Swift Code
import Foundation
typealias CompletionHandler = (Bool) -> Void
struct User {
let id: Int
var name: String?
func displayName() {
guard let name = name else {
print("Name is not set")
return
}
print("User name: \(name)")
}
}
extension User {
func isValid() -> Bool {
return name != nil && !name!.isEmpty
}
}
VB.NET Coding Standards
Naming
- Keep PascalCase for methods, camelCase for locals.
Class order
- Fields → Properties → Constructors → Methods → Events.
Interop
- Keep all P/Invoke declarations in a dedicated module.