Code Generator

Generate clean, well-documented code from a description

beginner
codinggenerationtypescriptpython

Prompt Template

Write {language} code that {description}.

Requirements:
- {requirements}
- Include error handling
- Add inline comments explaining key logic
- Follow {language} best practices

Variables

{language}

Example: TypeScript

{description}

Example: fetches user data from an API and caches it

{requirements}

Example: Use fetch API, cache for 5 minutes, handle network errors

Example Output

```typescript
interface User { id: number; name: string; email: string; }

const cache = new Map<string, { data: User; expiry: number }>();

async function fetchUser(id: number): Promise<User> {
  const cacheKey = `user_${id}`;
  const cached = cache.get(cacheKey);
  if (cached && cached.expiry > Date.now()) return cached.data;
  // ... fetch and cache logic
}
```

Tips

  • Be specific about edge cases
  • Mention framework/library preferences

More Prompts