Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contributing

How code gets into Open.Database.Extensions (ODX): the code rules a reviewer checks, and the habits that keep a change small, correct and easy to review. Documentation has its own guide: [docsite/CONTRIBUTING-DOCS.md](docsite/CONTRIBUTING-DOCS.md).

## Code

### Layout

- **Chains.** The first call stays on the line of what it is called on; from the second call on, one call per line. A single call stays on one line. Never leave a bare receiver alone on a line.
- **Line width.** About 80 columns, a soft limit. An expression body's `=>` goes on the next line.
- **Arguments.** Keep a call on one line when it fits. When it does not, break the arguments into groups that belong together, one group per line. A long run of one-argument lines is a sign to regroup.
- **Braces.** A header that wraps over two or more lines always gets braces, even for one statement. A one-line header with one short statement may skip them (`csharp_prefer_braces = when_multiline`).

### Resources and async

- **`using`, not `try`/`finally`.** A type that owns something to release is `IDisposable` (or `IAsyncDisposable`), and the call site is a `using` declaration. For an async disposal: `await using var _ = resource.ConfigureAwait(false);`. A `finally` is only for what a dispose cannot express, such as keeping the original exception when the dispose also fails, with a comment saying why.
- **`ConfigureAwait(false)`** on every await in library code.
- **No needless `async`.** A method that only hands a task on returns it.
- **`ValueTask`** where a call can complete synchronously on a realistic path; `Task` where it cannot.

### Errors

- **Every exception says what is wrong and what to do.** Name the object or parameter, the cause, and the fix ("Call the query's terminal first, then await the capture.").
- **Guard once, at the public entry point,** with the right parameter name. Internal code trusts it and uses `Debug.Assert`. Our code never throws `NullReferenceException`.
- **A misuse the compiler can catch is a compile error,** not a runtime throw, when that costs little API.

### Performance

- **State the cost.** A change on a per-call or per-row path says what it adds (a type check per call, an allocation per row) in its pull request.
- **No allocating string work** (`Trim`, `Split`, `Substring`, regex on strings) on these paths: use `ReadOnlySpan<char>`.
- **Flags are read with a mask** (`(options & Flag) != 0`), never `HasFlag`.
- **Generated code is at least as fast as hand-written code.** Parity is the floor, not the goal.
- **Benchmarks consume what they measure** (return it, or keep it alive), so the compiler cannot remove the work. A small gap counts only when it repeats and is larger than an A/A run of the same code.

### Members and types

- Members of an `internal` type are `public` or private, not `internal`.
- Use the `field` keyword for a lazy or custom-accessor property instead of a private backing field.
- An overload that takes a `CancellationToken` lets the token be passed positionally at every level.

## Pull requests

- **One topic, small enough to review.** Plan the split before building: one part of a feature per pull request. A pull request that keeps growing is split, not finished.
- **The description is the commit message.** Pull requests are squash-merged, so the description says what the change does now, its decisions, and the checks that ran, never "follow-up commits on this branch".
- **Checks before review:** a Release build with no warnings; tests in Release and Debug; the docs samples; `dotnet format` style and analyzers at `--severity info`; the docs build; a Visual Studio MSBuild build.
- **No local details** in code, commits or descriptions: no machine paths, user names or private notes.

## Habits

- **Measure or probe before you claim.** A statement about provider or runtime behavior ("SQL Server refuses this", "this name matches that parameter") is backed by a small test against a real database or the real runtime, not by reasoning alone.
- **Before calling something a regression, run the same test on the last release.** Timing-sensitive tests (GC, thread pool, stall timeouts) can pass by luck; force the condition (for example, collect explicitly) before trusting a pass or a fail.
- **Before fixing a bug, ask whether real code can reach it.** A failure that needs a setup no working application has (an unreferenced, stuck pipeline) is not worth a guard on the normal path.
- **Fix the cause.** Do not hide a failure by changing the test to avoid it.
- **Write down who decided.** A design note records each decision and its source: the maintainer, or a proposal still waiting for one.
- **Stay in scope.** Do not add requirements the release does not have (a platform, a check, a feature) without asking.