Skip to content
This repository was archived by the owner on Mar 22, 2026. It is now read-only.

Latest commit

 

History

History
62 lines (36 loc) · 2.32 KB

File metadata and controls

62 lines (36 loc) · 2.32 KB

Code hygiene

Intention

This document defines universal coding conventions for keeping codebases simple, coherent, and easy to evolve. In this context, duplication includes semantically equivalent code that can be deduplicated with small, low-risk refactoring. It is not limited to textually identical snippets.

Rule: Overloads delegate to a canonical implementation

If multiple overloads represent the same operation, choose one canonical implementation and delegate the other overloads to it.

How to verify

  • Overloads do not re-implement the same logic (even if the code is not textually identical), for example serialization, schema loading, or common request building.
  • A reader can point to one canonical overload that contains the real implementation.

How to fix

  • Keep one overload as canonical.
  • Rewrite other overloads to delegate to it by adapting parameters.

Exceptions

  • External API compatibility, when the overload set is constrained by a public interface.

Rule: Prefer abstractions in dependencies

Prefer constructor parameters, fields, and method signatures typed as interfaces or abstract classes. Use a concrete class type only when you need an API that is not available via an abstraction.

How to verify

  • Constructor-injected dependencies are typed as stable abstractions, not as implementation classes.
  • A class does not expose its internal implementation details in its public API via concrete types.

How to fix

  • Change dependency types to existing interfaces/abstract classes when available.
  • If the dependency library has no suitable abstraction, wrap it with a local interface and inject that instead.

Exceptions

  • Framework constraints where only a concrete type is injectable or proxied.
  • Value types and data records where an abstraction would reduce clarity.

Rule: No dead parameters in shared helpers

Do not add or keep parameters that do not change observable behavior at any call site.

How to verify

  • Every parameter is used either in the function body or by at least one call site for an observable behavior difference.

How to fix

  • Remove the parameter and simplify call sites.
  • If the parameter must exist for compatibility, deprecate it and record a removal plan.

Exceptions

  • Public API stability requirements, when the parameter cannot be removed yet.