هيكل توليد الكود
مثال عملي: dedupe function متعملة صح
دي نفس مهمة dedupe من الدرس الأول، متعاد كتابتها بـ skeleton الأربع blocks:
Write a Python function
dedupe_preserve_order(items: list[str]) -> list[str].Constraints:
- O(n) time and O(n) extra memory.
- Preserve first-seen order.
- Case-sensitive ("Apple" and "apple" are distinct).
- No external imports.
- Type hints required.
Include 4
asserttest cases inside anif __name__ == "__main__":block:
- Empty list returns
[].- Single-item list returns the same list.
["a","b","a","c","b"]returns["a","b","c"].- Case-sensitivity:
["Apple","apple","Apple"]returns["Apple","apple"].Output ONLY a single Python code block, no prose around it.
ده اللي رجّعه Claude Sonnet 4.5:
def dedupe_preserve_order(items: list[str]) -> list[str]:
seen: set[str] = set()
result: list[str] = []
for item in items:
if item not in seen:
seen.add(item)
result.append(item)
return result
if __name__ == "__main__":
assert dedupe_preserve_order([]) == []
assert dedupe_preserve_order(["a"]) == ["a"]
assert dedupe_preserve_order(["a", "b", "a", "c", "b"]) == ["a", "b", "c"]
assert dedupe_preserve_order(["Apple", "apple", "Apple"]) == ["Apple", "apple"]
Captured from Claude Sonnet 4.5 (claude-sonnet-4-5) on 2026-04-27. Re-runs may differ slightly.
تدفق التفكير اللي طلّع المخرج ده:
قارن سطر-بسطر مع مخرج الدرس الأول:
| الدرس الأول (prompt غامض) | الدرس الخامس (skeleton) |
|---|---|
| Functions اتنين بنفس الاسم | Function واحدة، signature واحد |
| مفيش type hints | Type hints كاملة، بما فيها seen: set[str] |
| مفيش tests | 4 asserts، واحد لكل خاصية |
| Markdown headings، prose، implementations اتنين | Code block واحد، مفيش حاجة حواليه |
نسختين O(n) و O(?) | Implementation واحد O(n)، مقفول بالـ constraint |
تقدر تعمل python dedupe.py للملف ده على طول. لو الـ asserts عدّت، تقدر تـcommit. ده الفرق اللي بيعمله prompt متشكّل كويس — 6 دقايق كتابة prompt بحرص بدل 45 دقيقة من loops accept-edit-test-fix.
ملاحظة على اللي ما حصلش: الموديل ما عملش over-engineering. ما ضفش Generic[T] type variable، ما كتبش docstring، ما عاملش handle لـ None، ما ضفش CLI wrapper. ليه؟ عشان مفيش حاجة من دول كانت في INTENT أو CONSTRAINTS. شغل الـ skeleton إنه يدّي للموديل المساحة الكافية بالظبط للشغل، وبس.
لما تبدأ تستخدم الـ skeleton ده على كود حقيقي، هتلاقي الـ constraints list بتكبر مع conventions الـ team: "اتبع style بتاعنا: 2-space indent، مفيش trailing commas، composition أحسن من inheritance." احفظهم كـ snippet. الـ constraints list بتبقى تعبير محمول عن طريقة الـ team في كتابة الكود.
Module جاي: تطبيق نفس الانضباط على debugging. :::
سجّل الدخول للتقييم