Claude-code-best-practice helps developers improve their coding skills by providing best practice guidance and feedback. It benefits operations teams by ensuring code quality and consistency. It connects to Python workflows and integrates with Claude AI for real-time suggestions.
git clone https://github.com/shanraisshan/claude-code-best-practice.gitClaude-code-best-practice helps developers improve their coding skills by providing best practice guidance and feedback. It benefits operations teams by ensuring code quality and consistency. It connects to Python workflows and integrates with Claude AI for real-time suggestions.
1. **Prepare Your Code:** Copy the Python code snippet you want to review into your clipboard. For best results, include at least 10-20 lines of relevant code. 2. **Invoke the Skill:** Paste the prompt template into your AI assistant (Claude/ChatGPT) and replace [CODE_SNIPPET] with your actual code. For large files, consider sharing only the relevant sections. 3. **Contextualize (Optional):** Add specific context in the prompt about your use case. For example: 'This code runs in a production environment handling 10,000 requests/hour' or 'This is part of a data processing pipeline.' 4. **Review and Iterate:** Apply the suggested improvements to your code. If you're unsure about any recommendation, ask the AI to explain the trade-offs or provide alternatives. 5. **Automate Checks:** For ongoing projects, integrate these checks into your development workflow. Use tools like pylint or flake8 with custom rules based on the AI's feedback to catch issues early. **Pro Tips:** - For new projects, run this check before committing code to version control - Focus on one type of issue at a time (e.g., security first, then performance) - Compare before/after versions to see the impact of improvements - Use the AI's suggestions to create team coding standards
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/shanraisshan/claude-code-best-practiceCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Act as a Python code quality advisor. Review the following Python code snippet: [CODE_SNIPPET]. Identify potential issues including: 1) PEP 8 style violations, 2) anti-patterns or bad practices, 3) performance bottlenecks, 4) security vulnerabilities, 5) missing documentation. Provide specific improvement suggestions with code examples. Focus on maintainability and scalability for production environments.
Here's a review of a Python script that processes user uploads in a web application:
**Original Code:**
```python
def process_upload(file_path):
with open(file_path, 'r') as f:
data = f.read()
lines = data.split('\n')
for line in lines:
if line.strip():
process_line(line)
```
**Issues Identified:**
1. **Resource Management:** The file handle isn't explicitly closed (though the `with` statement handles this, it's good practice to be explicit). Consider using `try/finally` for more complex scenarios.
2. **Memory Efficiency:** Reading the entire file into memory with `f.read()` is problematic for large files. This could cause memory issues with files >100MB.
3. **Error Handling:** No try-catch block for file operations. What happens if the file doesn't exist or isn't readable?
4. **Documentation:** Missing docstring and type hints. Future maintainers won't know the expected input/output.
5. **Performance:** The `split('\n')` creates an unnecessary intermediate list. Consider iterating directly over the file object.
**Improved Version:**
```python
def process_upload(file_path: str) -> None:
"""Process a user upload file line by line with proper error handling.
Args:
file_path: Path to the file to process
Raises:
FileNotFoundError: If file doesn't exist
PermissionError: If file isn't readable
ValueError: If file is empty or invalid
"""
try:
with open(file_path, 'r') as f:
for line in f:
if line.strip():
process_line(line.strip())
except FileNotFoundError as e:
raise FileNotFoundError(f"Upload file not found: {file_path}") from e
except PermissionError as e:
raise PermissionError(f"No permission to read file: {file_path}") from e
except Exception as e:
raise ValueError(f"Error processing file {file_path}: {str(e)}") from e
```
**Additional Recommendations:**
- Consider adding file size validation before processing
- Implement logging for debugging and monitoring
- Add unit tests for edge cases (empty files, special characters)
- For production, consider using a streaming approach with `yield` for very large files
- Add input validation for the file_path parameterAI assistant built for thoughtful, nuanced conversation
IronCalc is a spreadsheet engine and ecosystem
ITIL-aligned IT service management platform
Customer feedback management made simple
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan