Code Generation¶
Generate, explain, and improve code with Fabric.
Generating Code¶
Basic Generation¶
Simply describe what you want:
With Requirements¶
Be specific for better results:
Write a TypeScript function that:
- Validates email addresses using regex
- Returns a validation result with error messages
- Handles edge cases like empty strings
- Includes JSDoc comments
In Context¶
Provide context for integration:
I have this React component:
[paste component]
Add form validation that shows errors below each field
Code Explanation¶
Understanding Code¶
Line-by-Line Analysis¶
Complexity Analysis¶
Code Improvement¶
Refactoring¶
Performance¶
Best Practices¶
Tips for Better Results¶
1. Provide Context¶
Bad:
Good:
Write a sort function for an array of user objects.
Sort by lastName, then firstName.
Handle null/undefined values gracefully.
2. Specify Language/Framework¶
Bad:
Good:
3. Include Error Handling Requirements¶
Write an API client that:
- Fetches user data
- Handles network errors
- Retries failed requests up to 3 times
- Times out after 10 seconds
4. Ask for Tests¶
Agentic Code Generation¶
Enable agentic mode for complex tasks:
Create a complete authentication system with:
- Login/logout functionality
- Password reset flow
- Session management
- Rate limiting
Fabric will:
- Plan the implementation
- Create necessary files
- Write the code
- Generate tests
- Present for review