Code Style Guide¶
This document defines the official coding standards, architectural conventions, formatting principles, and engineering practices used throughout Aniwa.
The goal of this guide is to ensure that Aniwa remains:
- maintainable
- scalable
- readable
- contributor-friendly
- production-quality
over the long term.
Philosophy¶
Aniwa code should feel:
Why Code Style Matters¶
Consistent code style improves:
- maintainability
- onboarding
- debugging
- scalability
- collaboration
Core Engineering Principles¶
Aniwa follows several engineering principles:
| Principle | Meaning |
|---|---|
| readability | code should be easy to understand |
| simplicity | avoid unnecessary complexity |
| modularity | isolated responsibilities |
| scalability | future-friendly design |
| consistency | predictable patterns |
| maintainability | sustainable engineering |
General Philosophy¶
Prefer code that is:
Readability First¶
Readable code is more valuable than:
- compressed code
- overly clever abstractions
- unnecessary optimizations
File Organization Philosophy¶
Files should remain:
Good File Characteristics¶
A good file should:
- have a clear responsibility
- remain reasonably sized
- avoid unrelated logic
Bad File Characteristics¶
Avoid files that:
- contain many unrelated systems
- mix responsibilities
- become excessively large
Module Philosophy¶
Modules should represent:
Example Good Separation¶
Example:
Naming Philosophy¶
Names should be:
- descriptive
- predictable
- explicit
Good Variable Names¶
Examples:
Bad Variable Names¶
Avoid:
unless context is extremely obvious.
Function Naming¶
Functions should describe:
Good Function Names¶
Examples:
Bad Function Names¶
Avoid vague names like:
without context.
Class Naming¶
Classes should use:
Example¶
Examples:
Function Length Philosophy¶
Functions should remain:
Why Small Functions Matter¶
Small functions improve:
- readability
- testing
- debugging
Recommended Function Characteristics¶
Functions should ideally:
- perform one task
- remain easy to scan
- avoid excessive nesting
Avoid Deep Nesting¶
Prefer:
over:
Example Preferred Style¶
Good:
Example Avoided Style¶
Avoid:
Line Length¶
Recommended line length:
Why Reasonable Line Length Matters¶
This improves:
- readability
- diffs
- side-by-side review
Import Organization¶
Imports should be grouped logically.
Import Order¶
Recommended order:
Example¶
Example:
import json
from pathlib import Path
import polars as pl
import typer
from aniwa.core.profiler import profile_dataframe
Type Hint Philosophy¶
Aniwa strongly encourages:
Why Type Hints Matter¶
Type hints improve:
- readability
- tooling
- maintainability
- debugging
Example Type Hints¶
Example:
Avoid Ambiguous Types¶
Prefer:
over:
Enum Philosophy¶
Use enums for:
- controlled values
- CLI options
- internal constants
Example¶
Example:
Constants Philosophy¶
Shared constants should be centralized.
Example¶
Example:
Avoid Magic Values¶
Avoid unexplained hardcoded values.
Bad Example¶
Avoid:
Good Example¶
Prefer:
Comment Philosophy¶
Comments should explain:
not:
Avoid Obvious Comments¶
Avoid:
Good Comments¶
Prefer comments that explain:
- reasoning
- architecture
- tradeoffs
Docstring Philosophy¶
Public functions should include docstrings.
Example¶
Example:
Error Handling Philosophy¶
Errors should be:
- explicit
- informative
- actionable
Good Error Example¶
Example:
Avoid Silent Failures¶
Never suppress important failures silently.
Exception Philosophy¶
Catch exceptions only when:
- adding context
- recovering gracefully
- improving UX
Avoid Broad Exceptions¶
Avoid:
Prefer Explicit Exceptions¶
Prefer:
Logging Philosophy¶
Future logging systems should prioritize:
- clarity
- usefulness
- debuggability
Architecture Philosophy¶
Systems should remain:
Separation of Concerns¶
Avoid mixing:
| Concern | Example |
|---|---|
| profiling | reporting |
| rendering | parsing |
| CLI | business logic |
Business Logic Placement¶
Business logic belongs in:
not:
Template Philosophy¶
Templates should contain:
- presentation logic only
Reader Philosophy¶
Readers should:
- only ingest data
- avoid profiling logic
Renderer Philosophy¶
Renderers should:
- only render outputs
- avoid business logic
Testing Philosophy¶
Every important feature should include tests.
Test Organization¶
Tests belong in:
Recommended Test Naming¶
Examples:
Test Philosophy¶
Tests should validate:
- correctness
- edge cases
- regressions
Edge Cases Matter¶
Always test:
- empty datasets
- malformed inputs
- invalid configs
- extreme values
Performance Philosophy¶
Optimize only when necessary.
Avoid Premature Optimization¶
Prefer:
before:
Vectorization Philosophy¶
Prefer:
over:
Why Vectorization Matters¶
Vectorization improves:
- speed
- scalability
- memory efficiency
Configuration Philosophy¶
Configuration systems should remain:
- predictable
- validated
- user-friendly
CLI Philosophy¶
CLI systems should prioritize:
- simplicity
- discoverability
- consistency
Naming Conventions¶
| Element | Convention |
|---|---|
| files | snake_case |
| functions | snake_case |
| classes | PascalCase |
| constants | UPPER_CASE |
| variables | snake_case |
File Naming Examples¶
Good:
Bad:
Formatting Tools¶
Recommended tools:
| Tool | Purpose |
|---|---|
| black | formatting |
| ruff | linting |
| pytest | testing |
Black Formatting¶
Recommended command:
Ruff Linting¶
Recommended command:
Pytest¶
Recommended command:
Pull Request Philosophy¶
PRs should remain:
- focused
- reviewable
- isolated
Good Pull Requests¶
Good PRs:
- solve one problem
- include tests
- update documentation
Avoid Large Mixed PRs¶
Avoid PRs that:
- solve unrelated issues
- refactor everything simultaneously
- mix formatting with features
Documentation Philosophy¶
Documentation is considered:
Why Documentation Matters¶
Good documentation improves:
- contributor scalability
- project longevity
- onboarding
Contributor Philosophy¶
Contributors should prioritize:
- clarity
- maintainability
- architectural consistency
Long-Term Engineering Philosophy¶
Aniwa is designed for:
not:
Future Scalability Philosophy¶
Code written today should remain understandable:
Final Philosophy¶
Aniwa code should feel:
Every contributor helps shape:
Related Documentation¶
Continue with:
- architecture/system-design.md
- architecture/overview.md
- developer-guide/testing.md
- CONTRIBUTING.md