基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill clean-code命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | Clean Code |
| description | Principles and practices for writing readable, maintainable, and expressive code |
| category | software-development |
I help developers write code that is easy to understand, maintain, and extend. Clean code is about respecting both machines and humans—code that works correctly today and can be understood and modified by other developers (or your future self) tomorrow. I encompass naming conventions, function design, formatting, error handling, and overall code organization that prioritizes clarity over cleverness.
Apply clean code principles to all production code that will be maintained over time. Clean code matters most in collaborative environments where multiple developers read and modify the same codebase. Use these practices when writing new features, during code reviews, when debugging, or when refactoring legacy code. Avoid over-engineering one-off scripts or exploratory code where maintainability is not a concern.
from datetime import datetime, timedelta
# Bad
def get_things(a, b):
lst = []
for i in range(a):
for x in lst:
if x.status == 1:
x.status = 2
return lst
# Good
class Task:
def __init__(self, task_id: int, title: str):
self.task_id = task_id
self.title = title
self.status: TaskStatus = TaskStatus.PENDING
class TaskStatus:
PENDING = 1
IN_PROGRESS = 2
COMPLETED = 3
def activate_pending_tasks(
tasks: list[Task],
days_ago: int = 30
) -> list[Task]:
cutoff_date = datetime.now() - timedelta(days=days_ago)
activated_tasks: list[Task] = []
for task in tasks:
if task.status == TaskStatus.PENDING:
task.status = TaskStatus.IN_PROGRESS
activated_tasks.append(task)
return activated_tasks
from decimal import Decimal
from typing import Optional
# Bad - One function doing too much
def process_order(order_data: dict) -> dict:
validate_order(order_data)
calculate_totals(order_data)
apply_discounts(order_data)
save_order(order_data)
send_confirmation(order_data)
update_inventory(order_data)
return order_data
# Good - Each function does one thing
def validate_order(order_data: dict) -> None:
required_fields = ["customer_id", "items", "shipping_address"]
for field in required_fields:
if field not in order_data:
raise ValueError(f"Missing required field: {field}")
def calculate_order_totals(order: dict) -> None:
subtotal = sum(item["price"] * item["quantity"] for item in order["items"])
tax = subtotal * Decimal("0.08")
order["subtotal"] = subtotal
order["tax"] = tax
order["total"] = subtotal + tax
def apply_discounts(order: , discount_code: [] = ) -> :
discount_code == :
order[] *= Decimal()
order[] =
() -> :
validate_order(order_data)
calculate_order_totals(order_data)
apply_discounts(order_data, discount_code)
saved_order = save_order(order_data)
send_confirmation(saved_order)
update_inventory(saved_order)
saved_order
from contextlib import contextmanager
from typing import Generator
class InsufficientFundsError(Exception):
def __init__(self, balance: float, withdrawal: float):
self.balance = balance
self.withdrawal = withdrawal
super().__init__(f"Insufficient funds: {balance} < {withdrawal}")
class AccountClosedError(Exception):
pass
class BankAccount:
def __init__(self, account_id: str, initial_balance: float = 0):
self.account_id = account_id
self._balance = Decimal(str(initial_balance))
self._is_active = True
@property
def balance(self) -> float:
return float(self._balance)
def deposit(self, amount: float) -> None:
if amount <= :
ValueError()
._is_active:
AccountClosedError(.account_id)
._balance += Decimal((amount))
() -> :
amount <= :
ValueError()
._is_active:
AccountClosedError(.account_id)
amount > ._balance:
InsufficientFundsError((._balance), amount)
._balance -= Decimal((amount))
() -> Generator[BankAccount, , ]:
:
account
Exception e:
()
from datetime import datetime
from typing import NamedTuple
class UserCredentials(NamedTuple):
username: str
password_hash: str
salt: str
class AuthenticationResult(NamedTuple):
success: bool
user_id: int | None = None
error_message: str | None = None
class PasswordHasher:
@staticmethod
def hash(password: str, salt: str) -> str:
import hashlib
return hashlib.sha256(f"{password}{salt}".encode()).hexdigest()
@staticmethod
def verify(
password: str,
salt: str,
expected_hash: str
) -> bool:
return PasswordHasher.hash(password, salt) == expected_hash
def authenticate_user(
credentials: UserCredentials,
stored_credentials: dict[str, UserCredentials]
) -> AuthenticationResult:
credentials.username stored_credentials:
AuthenticationResult(success=)
stored = stored_credentials[credentials.username]
PasswordHasher.verify(
credentials.password,
stored.salt,
stored.password_hash
):
AuthenticationResult(success=)
AuthenticationResult(success=, user_id=(credentials.username))
from dataclasses import dataclass
from enum import Enum
from typing import Protocol, runtime_checkable
class OrderStatus(Enum):
PENDING = "pending"
CONFIRMED = "confirmed"
SHIPPED = "shipped"
DELIVERED = "delivered"
CANCELLED = "cancelled"
@dataclass(frozen=True)
class OrderItem:
product_id: str
quantity: int
unit_price: float
@property
def total_price(self) -> float:
return self.quantity * self.unit_price
@dataclass
class ShippingAddress:
street: str
city: str
state: str
zip_code: str
country: str
@dataclass
class Order:
order_id: str
customer_id: str
items: list[OrderItem]
shipping_address: ShippingAddress
status: OrderStatus = OrderStatus.PENDING
created_at: datetime = None
@property
def total_amount() -> :
(item.total_price item .items)
():
() -> :
() -> Order | :