Home → Documentation → Contributing → Code Style
Code should be:
When faced with two implementations of equal performance, always choose the simpler one.
Every implementation should respect project boundaries.
Foundation
↑
Runtime
↑
GraphQL
Never introduce shortcuts that violate dependency direction.
Architectural consistency is more important than reducing a few lines of code.
One public type per file.
Example:
EntityMetadata.cs
QueryPlanner.cs
GeneratedMetadataProvider.cs
Avoid grouping unrelated public types in the same file.
Names should describe intent.
Prefer:
ResolveJoinMetadata()
BuildMutationPlan()
WriteConflictClause()
Instead of:
Resolve()
Build()
Write()
Variables should also be descriptive.
Good:
entityMetadata
columnReference
joinMetadata
Avoid:
x
tmp
obj
data
Methods should generally perform one logical task.
Large methods should be decomposed into private helpers.
Instead of:
BuildEverything()
Prefer:
ResolveMetadata()
BuildProjection()
BuildOrdering()
BuildFilters()
Small methods are easier to understand and test.
Prefer immutable types.
Example:
public sealed class EntityMetadata
{
public ushort Id { get; }
public string Name { get; }
public ImmutableArray<ColumnMetadata> Columns { get; }
}
Mutable state should be limited to execution-specific objects.
Throw exceptions only for exceptional situations.
Validation errors should occur during planning or generation whenever possible.
Runtime should rarely encounter invalid metadata.
Comments should explain why, not what.
Good:
// Preserve deterministic alias ordering for snapshot stability.
Avoid:
// Increment i.
i++;
Code should be self-explanatory whenever possible.
| ← Previous: Contributing | Next: Testing → |