File size: 1,961 Bytes
3c88a0f | 1 2 3 4 5 | {"type": "session", "harness": "deepseek-harness", "id": "bad002", "name": "Anti-patterns and code smells"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "What are common anti-patterns and code smells?"}}
{"type": "message", "message": {"role": "assistant", "content": "**Code Smells:**\n- Long methods (>50 lines)\n- Large classes (>500 lines)\n- Deep nesting (3+ levels)\n- Duplicated code\n- Long parameter lists (>3 parameters)\n- Dead code (unused variables, unreachable code)\n- God objects (do everything)\n\n**Anti-Patterns:**\n\n1. **Spaghetti Code:** No structure, tangled logic\n```python\n# Bad: everything in one function\n\n # 200 lines of mixed logic\n```\n\n2. **Golden Hammer:** Using same tool for everything\n```python\n# Bad: regex for HTML parsing\nre.findall(r'<div>(.*?)</div>', html)\n```\n\n3. **Copy-Paste Programming:** Duplicated logic\n```python\n# Bad: same validation everywhere\nif age >= 18 and age <= 65 and country == \"US\": ...\n# repeated 10 times\n```\n\n4. **Premature Optimization:** Optimizing before needed\n```python\n# Bad: complex cache for simple operation\n@lru_cache(maxsize=1024)\ndef add(a, b): return a + b\n```\n\n5. **Lava Flow:** Dead code that nobody dares remove\n\n6. **Shotgun Surgery:** One change requires many edits\n\n7. **Feature Envy:** Method uses another class's data more than its own\n\n8. **Primitive Obsession:** Using primitives instead of small objects\n```python\n# Bad\nname = \"John\"\nage = 30\n# Better: use a Person class\n```"}}
|