|
| 1 | +# Naming And Structure Conventions |
| 2 | + |
| 3 | +This document defines the naming and structure rules for KPaper to keep the API consistent, readable, and backward-compatible. |
| 4 | + |
| 5 | +## Package Naming |
| 6 | + |
| 7 | +- Use lowercase package names only. |
| 8 | +- Keep feature-oriented package roots under `cc.modlabs.kpaper`: |
| 9 | + - `command`, `coroutines`, `event`, `extensions`, `file`, `game`, `inventory`, `main`, `messages`, `npc`, `party`, `scoreboard`, `util`, `visuals`, `world`. |
| 10 | +- Prefer singular package names for feature domains (for example `event`, not `events`) unless a package already exists and changing it would break users. |
| 11 | + |
| 12 | +## Type And File Naming |
| 13 | + |
| 14 | +- Classes/interfaces/object names use `PascalCase`. |
| 15 | +- Function/property names use `camelCase`. |
| 16 | +- Constants use `UPPER_SNAKE_CASE`. |
| 17 | +- Avoid abbreviations unless widely understood (`api`, `uuid`, `url`, `json`). |
| 18 | +- File name should match the main public type when a file is type-centric. |
| 19 | + |
| 20 | +## Public API Naming |
| 21 | + |
| 22 | +- Prefer explicit verbs for functions (`parseLocation`, `locationToString`). |
| 23 | +- Boolean names must use `is`, `has`, `can`, or `should`. |
| 24 | +- Avoid typo-prone names and legacy shorthand (`str2Loc`, `loc2Str`). |
| 25 | + |
| 26 | +## Backward Compatibility Policy |
| 27 | + |
| 28 | +- Never remove/rename public API directly in normal releases. |
| 29 | +- For naming fixes: |
| 30 | + 1. Add the new canonical API. |
| 31 | + 2. Keep the old API as a deprecated bridge. |
| 32 | + 3. Use `ReplaceWith(...)` for IDE-assisted migration. |
| 33 | +- Keep compatibility bridges for at least one full CalVer cycle unless intentionally breaking. |
| 34 | + |
| 35 | +### Current Migration Map |
| 36 | + |
| 37 | +- `sendEmtpyLine` -> `sendEmptyLine` |
| 38 | +- `removePersistantDataIf` -> `removePersistentDataIf` |
| 39 | +- `str2Loc` -> `parseLocation` |
| 40 | +- `loc2Str` -> `locationToString` |
| 41 | +- `loc2BlockStr` -> `locationToBlockString` |
| 42 | +- `toSaveAbleString` -> `toSavableString` |
| 43 | +- `toSaveAbleBlockString` -> `toSavableBlockString` |
| 44 | +- `toSaveAbleDirectionalString` -> `toSavableDirectionalString` |
| 45 | +- `Inventory.clone(..., shuffeld=...)` -> `Inventory.cloneCompat(..., shuffled=...)` |
| 46 | +- `NAMESPACE_GUI_IDENTIFIER` -> `GUI_IDENTIFIER_KEY` |
| 47 | +- `NAMESPACE_ITEM_IDENTIFIER` -> `ITEM_IDENTIFIER_KEY` |
| 48 | + |
| 49 | +## Structure And Maintainability |
| 50 | + |
| 51 | +- Keep helper APIs close to their domain package. |
| 52 | +- Prefer small cohesive files over large mixed-purpose files. |
| 53 | +- Add KDoc for all public APIs and all deprecated bridge APIs. |
| 54 | +- Add tests for new behavior and migration bridges where feasible. |
| 55 | + |
| 56 | +## Performance Notes |
| 57 | + |
| 58 | +- Prefer allocation-light APIs for hot paths. |
| 59 | +- Avoid unnecessary reflection and repeated object creation in frequently called extensions. |
| 60 | +- Validate and cap untrusted inputs (size/time limits) in serialization and network paths. |
0 commit comments