Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 1.91 KB

CODING.md

File metadata and controls

55 lines (37 loc) · 1.91 KB

Coding Principles — Mock1299

Style

  • Follow PEP 8. Use ruff for linting and formatting.
  • Max line length: 120 characters.
  • Use type hints on function signatures. Skip them for obvious local variables.
  • Imports: stdlib → third-party → local, separated by blank lines. One import per line.

Naming

  • snake_case for modules, functions, variables.
  • PascalCase for classes.
  • UPPER_SNAKE for constants.
  • Private internals prefixed with _.

Structure

  • One responsibility per module. If a file grows past ~300 lines, split it.
  • Keep core/, ble/, gui/ boundaries clean — no GUI imports in core, no BLE imports in GUI.
  • Shared state flows through explicit arguments or queues, never module-level globals.

Error Handling

  • Validate at boundaries: CLI args, profile TOML parsing, BLE callbacks.
  • Internal code trusts its callers — don't over-validate between modules.
  • Log errors with structlog context, don't silently swallow exceptions.

Threading

  • All cross-thread data goes through queue.Queue or threading.Event.
  • Never share mutable state between threads without synchronization.
  • BLE and signal threads must not import or call GUI code directly.

Testing

  • Tests live in tests/ mirroring the source layout.
  • Test names: test_<what>_<expected_behavior>.
  • Unit tests must not require a BLE adapter or display server.
  • Use pytest. No unittest classes unless grouping is genuinely needed.

Dependencies

  • Pin minimum versions in pyproject.toml, not exact versions.
  • No new dependencies without justification — stdlib first.

Commits

  • Small, focused commits. One logical change per commit.
  • Message format: <area>: <what changed> (e.g., encoder: fix sign extension for negative µV).

Documentation

  • Docstrings on public functions only, one line when possible.
  • Comments explain why, not what. If the code needs a what comment, simplify the code.