clean-code
ما الذي تفعله
تساعد هذه المهارة في تحويل شيفرة تعمل لكنها صعبة الفهم إلى شيفرة نظيفة وسهلة القراءة. تتبع أفضل الممارسات لجعل الشيفرة أكثر تنظيمًا وقابلية للفهم من قبل المطورين الآخرين.
متى تستخدمها
- ✓عند كتابة شيفرة جديدة لضمان الجودة منذ البداية.
- ✓عند مراجعة شيفرة الآخرين لتقديم اقتراحات تحسين.
- ✓عند محاولة إصلاح أو تحسين شيفرة قديمة ومعقدة.
رابط المهارة
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/clean-code/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“أعد هيكلة هذه الشيفرة لتصبح أنظف وأسهل في الفهم، مع الحفاظ على وظيفتها.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يحلل الذكاء الاصطناعي الشيفرة التي تزوده بها، ويطبق قواعد « الشيفرة النظيفة ». يتضمن ذلك استخدام أسماء أوضح للمتغيرات والدوال، وتقسيم الشيفرة الطويلة إلى أجزاء أصغر ومركزة، وإزالة التعليقات غير الضرورية، لتصبح الشيفرة أسهل في القراءة.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Clean Code Skill
This skill embodies the principles of "Clean Code" by Robert C. Martin (Uncle Bob). Use it to transform "code that works" into "code that is clean."
🧠 Core Philosophy
"Code is clean if it can be read, and enhanced by a developer other than its original author." — Grady Booch
When to Use
Use this skill when:
- Writing new code: To ensure high quality from the start.
- Reviewing Pull Requests: To provide constructive, principle-based feedback.
- Refactoring legacy code: To identify and remove code smells.
- Improving team standards: To align on industry-standard best practices.
1. Meaningful Names
- Use Intention-Revealing Names:
elapsedTimeInDaysinstead ofd. - Avoid Disinformation: Don't use
accountListif it's actually aMap. - Make Meaningful Distinctions: Avoid
ProductDatavsProductInfo. - Use Pronounceable/Searchable Names: Avoid
genymdhms. - Class Names: Use nouns (
Customer,WikiPage). AvoidManager,Data. - Method Names: Use verbs (
postPayment,deletePage).
2. Functions
- Small!: Functions should be shorter than you think.
- Do One Thing: A function should do only one thing, and do it well.
- One Level of Abstraction: Don't mix high-level business logic with low-level details (like regex).
- Descriptive Names:
isPasswordValidis better thancheck. - Arguments: 0 is ideal, 1-2 is okay, 3+ requires a very strong justification.
- No Side Effects: Functions shouldn't secretly change global state.
3. Comments
- Don't Comment Bad Code—Rewrite It: Most comments are a sign of failure to express ourselves in code.
- Explain Yourself in Code:
vs# Check if employee is eligible for full benefits if employee.flags & HOURLY and employee.age > 65:if employee.isEligibleForFullBenefits(): - Good Comments: Legal, Informative (regex intent), Clarification (external libraries), TODOs.
- Bad Comments: Mumbling, Redundant, Misleading, Mandated, Noise, Position Markers.
4. Formatting
- The Newspaper Metaphor: High-level concepts at the top, details at the bottom.
- Vertical Density: Related lines should be close to each other.
- Distance: Variables should be declared near their usage.
- Indentation: Essential for structural readability.
5. Objects and Data Structures
- Data Abstraction: Hide the implementation behind interfaces.
- The Law of Demeter: A module should not know about the innards of the objects it manipulates. Avoid
a.getB().getC().doSomething(). - Data Transfer Objects (DTO): Classes with public variables and no functions.
6. Error Handling
- Use Exceptions instead of Return Codes: Keeps logic clean.
- Write Try-Catch-Finally First: Defines the scope of the operation.
- Don't Return Null: It forces the caller to check for null every time.
- Don't Pass Null: Leads to
NullPointerException.
7. Unit Tests
- The Three Laws of TDD:
- Don't write production code until you have a failing unit test.
- Don't write more of a unit test than is sufficient to fail.
- Don't write more production code than is sufficient to pass the failing test.
- F.I.R.S.T. Principles: Fast, Independent, Repeatable, Self-Validating, Timely.
8. Classes
- Small!: Classes should have a single responsibility (SRP).
- The Stepdown Rule: We want the code to read like a top-down narrative.
9. Smells and Heuristics
- Rigidity: Hard to change.
- Fragility: Breaks in many places.
- Immobility: Hard to reuse.
- Viscosity: Hard to do the right thing.
- Needless Complexity/Repetition.
🛠️ Implementation Checklist
- Is this function smaller than 20 lines?
- Does this function do exactly one thing?
- Are all names searchable and intention-revealing?
- Have I avoided comments by making the code clearer?
- Am I passing too many arguments?
- Is there a failing test for this change?
Example
User request:
Refactor this working code for clearer names, smaller units, explicit errors, and preserved behavior; verify it with focused tests.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
…
الأسئلة الشائعة
ما هي « الشيفرة النظيفة »؟
هي شيفرة يسهل على أي مطور قراءتها وفهمها، حتى لو لم يكن هو من كتبها أصلًا.
لماذا أستخدم أسماء أوضح في الشيفرة؟
الأسماء الواضحة تساعد على فهم ما تفعله الشيفرة دون الحاجة إلى شروحات إضافية. مثلًا « elapsedTimeInDays » أفضل من « d ».
ما هي « روائح الشيفرة »؟
هي مؤشرات في الشيفرة تدل على أن شيئًا ما قد يكون خاطئًا أو يمكن تحسينه، مثل الأسماء المربكة والدوال الطويلة جدًا والتكرار.
التفاصيل
الوصف الأصلي من المؤلف
This skill embodies the principles of \"Clean Code\" by Robert C. Martin (Uncle Bob). Use it to transform \"code that works\" into \"code that is clean.\
الشعبية
- نجوم GitHub
- 48k
- الترتيب
- #4151
- الترخيص
- MIT
- آخر تحديث
- 15/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
00-andruia-consultant
48kيساعد وكيلك على بدء مشاريع الذكاء الاصطناعي أو تحسينها. يحلل الكود ويقترح الأدوات ويُعد خطط عمل بالإسبانية.
007
48kيتيح لوكيلك إجراء تدقيقات أمنية ونمذجة التهديدات. مفيد لحماية المشاريع من الهجمات والثغرات الأمنية.
10-andruia-skill-smith
48kيساعد وكيلك على إنشاء أدوات الذكاء الاصطناعي أو تحسينها. يحدد طريقة عملها، ويكتب توثيقها، ويتحقق من بنيتها.
20-andruia-niche-intelligence
48kيتيح لوكيلك إعداد ملخص عن صناعة محددة. مفيد لفهم السياق والقواعد وأنماط الاستخدام والمخاطر لمشروع ما، باستخدام مصادر موثوقة.
مهارات مشابهة
diffs
394kيتيح لوكيلك إنتاج فرق تعديلات حقيقي يمكن مشاركته، كرابط عرض أو ملف صورة، بدلاً من ملخص مكتوب يدوياً.
coding-agent
394kيساعد وكيلك على تسليم مهمة برمجة كبيرة إلى Codex أو Claude Code أو OpenCode كعامل في الخلفية، ثم متابعة تقدمها.
gh-issues
394kيساعد وكيلك على إيجاد مشكلات GitHub واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.