← 教程列表
news

Solve, don't punt

📅 2026/6/12 16:30:02⏱ 约 5 分钟阅读👁 8 阅读

When writing scripts for Skills, handle error conditions rather than punting to Claude. **Good example: Handle errors explicitly**: ```python theme={null} def process_file(path): """Process a file, creating it if it doesn't exist.""" try: with open(path) as f: return f.read() except FileNotFoundError: # Create file with default content instead of failing print(f"File {path} not found, creating default") with open(path, 'w') as f: f.write('') return '' except PermissionError: # Provide alternative instead of failing print(f"Cannot access {path}, using default") return '' ``` **Bad example: Punt to Claude**: ```python theme={null} def process_file(path): # Just fail and let Claude figure it out return open(path).read() ``` Configuration parameters should also be justified and documented to avoid "voodoo constants" (Ousterhout's law). If you don't know the right value, how will Claude determine it? **Good example: Self-documenting**: ```python theme={null}

← 返回教程列表 AI8899 · 内容仅供学习参考