From 068e676fa4fb68d889f39489f06222cc03e31691 Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Wed, 2 Dec 2026 08:59:05 -0800 Subject: [PATCH] Contributing guide: the code rules a reviewer checks, and the habits behind them Adds CONTRIBUTING.md at the root: layout (chains, line width, argument groups, braces), resources and async (using over try/finally, ConfigureAwait, ValueTask), errors (messages that say the fix, one guard at the entry point), performance (state the cost, no allocating string work, masks over HasFlag, generated code at least hand-written speed, benchmarks that consume their results), pull requests (one topic, the description is the squash message, the checks), and the habits that kept reviews short: probe before claiming, compare with the last release before calling a regression, ask whether real code can reach a bug before guarding it, record who decided, stay in scope. Points to docsite/CONTRIBUTING-DOCS.md for documentation. Co-Authored-By: Claude Opus 5.5 --- CONTRIBUTING.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..7dc7e03d --- /dev/null +++ b/CONTRIBUTING.md @@ -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`. +- **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.