📚 docs: Record field declaration design discussion in papers
## Summary Documented the "init block vs fields-at-top" design discussion as a valuable example of AI-human collaboration in language design. ## Changes ### Paper G (AI Collaboration) - Added field-declaration-design.md documenting the entire discussion flow - Showcased how complex init block proposal evolved to simple "fields at top" rule - Demonstrates AI's tendency toward complexity vs human intuition for simplicity ### Paper H (AI Practical Patterns) - Added Pattern #17: "Gradual Refinement Pattern" (段階的洗練型) - Documents the process: Complex AI proposal → Detailed analysis → Human insight → Convergence - Field declaration design as a typical example ### Paper K (Explosive Incidents) - Added Incident #046: "init block vs fields-at-top incident" - Updated total count to 46 incidents - Shows how a single human comment redirected entire design approach ## Design Decision After analysis, decided that BoxIndex should remain a compiler-internal structure, not a core Box: - Core Boxes: User-instantiable runtime values (String, Integer, Array, Map) - Compiler internals: BoxIndex for name resolution (compile-time only) - Clear separation of concerns between language features and compiler tools ## Philosophy This discussion exemplifies key principles: - The best design needs no explanation - Constraints provide clarity, not limitation - "Everything is Box" doesn't mean "compiler internals are Boxes" - AI tends toward theoretical completeness; humans toward practical simplicity 🐱 Sometimes the simplest answer is right in front of us\!
This commit is contained in:
@ -33,6 +33,39 @@ Structure
|
||||
- Keep methods short and focused; prefer extracting helpers to maintain clarity.
|
||||
- Prefer pure helpers where possible; isolate I/O in specific methods.
|
||||
|
||||
Box layout
|
||||
- フィールドは box 本体の先頭にまとめる(先頭ブロック)。
|
||||
- 先頭フィールド群の後ろはメソッドのみを記述する(`birth` を含む)。
|
||||
- フィールド間の空行・コメントは許可。アノテーション(将来追加予定)もフィールド行の直前/行末を許可。
|
||||
- NG: 最初のメソッド以降にフィールドを追加すること(リンタ警告/厳格モードでエラー)。
|
||||
|
||||
良い例
|
||||
```nyash
|
||||
box Employee {
|
||||
// データ構造(フィールド)
|
||||
name: StringBox
|
||||
age: IntegerBox
|
||||
department: StringBox
|
||||
|
||||
// ここからメソッド
|
||||
birth(n, a, d) { me.name = n; me.age = a; me.department = d }
|
||||
promote() { }
|
||||
}
|
||||
```
|
||||
|
||||
悪い例(NG)
|
||||
```nyash
|
||||
box Bad {
|
||||
id: IntegerBox
|
||||
method1() { }
|
||||
name: StringBox // ❌ フィールドはメソッドの後に置けない
|
||||
}
|
||||
```
|
||||
|
||||
ツール
|
||||
- 警告: 既定は警告(`NYASH_CLI_VERBOSE=1` で詳細を表示)。
|
||||
- 厳格化: `NYASH_FIELDS_TOP_STRICT=1` でエラーに昇格(Runnerでチェック)。
|
||||
|
||||
Examples
|
||||
```nyash
|
||||
using core.std as Std
|
||||
@ -64,4 +97,3 @@ static box Main {
|
||||
CI/Tooling
|
||||
- Optional formatter PoC: see `docs/tools/nyfmt/NYFMT_POC_ROADMAP.md`.
|
||||
- Keep smoke scripts small and fast; place them under `tools/`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user