[Language/Framework]-Specific Prompts
Introduction
Language and framework-specific prompts are specialized instructions tailored to generate code for particular programming environments. This collection provides optimized templates that leverage the unique features, patterns, and best practices of specific languages and frameworks, resulting in more idiomatic and effective code generation.
Why Use Language-Specific Prompts
Generic prompts often produce functional but non-idiomatic code that fails to leverage language-specific features and patterns. Language-specific prompts offer several advantages:
Idiomatic Code: Generate code that follows language-specific conventions and best practices
Optimized Solutions: Leverage language-specific features for more efficient implementations
Framework Alignment: Properly utilize framework-specific patterns and architecture
Better Error Handling: Implement language-appropriate error handling strategies
Enhanced Security: Apply language-specific security practices
Python Prompts
Python General Template
SITUATION: Developing [describe component/feature] using Python [version]
CHALLENGE: Implement [specific functionality] following Pythonic principles
AUDIENCE: Python developers familiar with [beginner/intermediate/advanced] concepts
FORMAT:
- Follow PEP 8 style guidelines
- Use descriptive variable and function names
- Implement appropriate error handling with specific exceptions
- Include docstrings for all functions/classes (Google style)
- Apply type hints where appropriate
FOUNDATIONS:
- Use Python's built-in functions where applicable
- Follow the principle "better to ask forgiveness than permission" (EAFP)
- Leverage list/dict comprehensions where appropriate
- Use generator expressions for large datasets
- Implement proper resource handling (context managers)
SPECIFIC REQUIREMENTS:
- Compatible with Python [version] and above
- Minimize external dependencies
- Include appropriate unit tests
- Handle edge cases properly
Django Framework Template
SITUATION: Building [describe feature] in a Django [version] project
CHALLENGE: Implement [specific component] following Django best practices
AUDIENCE: Django developers on a team project
FORMAT:
- Follow Django's MTV (Model-Template-View) architecture
- Apply Django coding style conventions
- Structure code for reusability and testing
- Include proper documentation
- Implement Django-specific patterns
FOUNDATIONS:
- Use Django's ORM features appropriately
- Implement proper form validation
- Follow Django security best practices
- Use Django's template system correctly
- Leverage Django's built-in authentication when relevant
- Apply appropriate model design patterns
SPECIFIC REQUIREMENTS:
- Create models with proper field types and relationships
- Implement clean, RESTful URL patterns
- Include proper permission checks
- Apply Django's caching mechanisms where appropriate
- Add appropriate admin interface customization
FastAPI Template
SITUATION: Building an API with FastAPI [version]
CHALLENGE: Create [specific endpoint/feature] with optimal performance and documentation
AUDIENCE: Backend developers working on a microservice architecture
FORMAT:
- Use FastAPI's dependency injection system
- Implement Pydantic models for requests/responses
- Follow async/await patterns where appropriate
- Structure for clear API documentation
- Include proper status codes and responses
FOUNDATIONS:
- Leverage FastAPI's automatic validation
- Implement proper error handling and status codes
- Use appropriate path and query parameters
- Apply security best practices (auth, validation)
- Optimize for performance where relevant
SPECIFIC REQUIREMENTS:
- Include complete OpenAPI documentation with examples
- Implement proper request validation
- Add appropriate response models
- Include authentication where needed
- Optimize database queries
JavaScript/TypeScript Prompts
JavaScript Modern Template
SITUATION: Developing [describe component/feature] using modern JavaScript (ES6+)
CHALLENGE: Implement [specific functionality] with clean, maintainable JavaScript
AUDIENCE: Frontend/Node.js developers working on [browser/server/both]
FORMAT:
- Use ES6+ features (destructuring, arrow functions, etc.)
- Apply functional programming principles where appropriate
- Follow Airbnb JavaScript style guide
- Implement proper error handling
- Include clear comments for complex logic
FOUNDATIONS:
- Leverage promises and async/await for asynchronous operations
- Use modern JS APIs when available
- Apply modular design principles
- Implement proper error handling
- Avoid global state and side effects where possible
SPECIFIC REQUIREMENTS:
- Ensure browser compatibility with [list browsers]
- Consider performance implications
- Handle error cases gracefully
- Implement proper memory management
- Protect against common JS vulnerabilities
TypeScript Template
SITUATION: Building [describe component/feature] with TypeScript [version]
CHALLENGE: Implement [specific functionality] with strong typing and TypeScript best practices
AUDIENCE: Developers familiar with TypeScript on a [frontend/backend/full-stack] project
FORMAT:
- Use proper TypeScript interfaces and types
- Follow TypeScript best practices
- Leverage advanced TypeScript features appropriately
- Maintain type safety throughout the code
- Include JSDoc comments for all public APIs
FOUNDATIONS:
- Use strict type checking
- Apply interface segregation principles
- Leverage TypeScript's structural typing
- Implement proper error handling with typed errors
- Use generics where appropriate for reusable code
- Apply discriminated unions for type narrowing
SPECIFIC REQUIREMENTS:
- Avoid any type where possible
- Implement proper null/undefined handling
- Use type guards for runtime type checking
- Apply strict null checking
- Structure for maintainability and readability
React Framework Template
SITUATION: Developing [describe component/feature] for a React [version] application
CHALLENGE: Create [specific component/functionality] following React best practices
AUDIENCE: React developers working on a team-based project
FORMAT:
- Use functional components with hooks
- Apply proper component composition
- Follow React naming conventions
- Implement clean props interfaces
- Structure for maintainability and testability
FOUNDATIONS:
- Apply single responsibility principle to components
- Implement proper state management
- Use appropriate hooks (useState, useEffect, useMemo, etc.)
- Handle side effects properly
- Apply proper performance optimizations
- Implement accessibility best practices
SPECIFIC REQUIREMENTS:
- Define clear prop interfaces with TypeScript
- Include proper error boundaries
- Implement responsive design considerations
- Add appropriate unit tests (React Testing Library preferred)
- Follow React performance best practices
Angular Framework Template
SITUATION: Building [describe feature] for an Angular [version] application
CHALLENGE: Implement [specific functionality] following Angular architectural principles
AUDIENCE: Angular developers on an enterprise application
FORMAT:
- Follow Angular style guide and conventions
- Use appropriate Angular decorators and metadata
- Structure code following Angular module patterns
- Implement proper component architecture
- Apply Angular dependency injection patterns
FOUNDATIONS:
- Use Angular services for shared functionality
- Implement proper reactive form validation
- Apply RxJS patterns correctly
- Follow OnPush change detection strategy where appropriate
- Use Angular routing features correctly
- Implement proper error handling with Angular ErrorHandler
SPECIFIC REQUIREMENTS:
- Include proper input/output bindings
- Implement appropriate lifecycle hooks
- Structure for lazy loading where applicable
- Apply proper template syntax
- Add unit tests with TestBed
Java Prompts
Java Modern Template
SITUATION: Developing [describe component/feature] using Java [version]
CHALLENGE: Implement [specific functionality] following modern Java best practices
AUDIENCE: Java developers on an enterprise application
FORMAT:
- Use Java coding conventions and naming standards
- Implement proper object-oriented design
- Apply appropriate design patterns
- Use Java Stream API where appropriate
- Include comprehensive exception handling
- Add proper JavaDoc comments
FOUNDATIONS:
- Leverage Java's type system effectively
- Apply immutability where appropriate
- Use functional interfaces for cleaner code
- Implement proper resource management
- Follow SOLID principles
- Use appropriate collection classes
SPECIFIC REQUIREMENTS:
- Ensure thread safety where needed
- Optimize performance for critical sections
- Implement proper logging
- Include appropriate unit tests
- Follow Java security best practices
Spring Boot Framework Template
SITUATION: Building [describe feature] with Spring Boot [version]
CHALLENGE: Create [specific component/service] following Spring best practices
AUDIENCE: Spring developers on an enterprise application
FORMAT:
- Follow Spring Boot conventions
- Use appropriate Spring stereotypes
- Implement proper dependency injection
- Structure according to Spring application layers
- Apply Spring Boot auto-configuration appropriately
FOUNDATIONS:
- Use Spring's dependency injection correctly
- Implement proper exception handling
- Apply appropriate Spring security practices
- Use Spring Data repositories where appropriate
- Leverage Spring Boot starters effectively
- Implement proper configuration management
SPECIFIC REQUIREMENTS:
- Implement proper transactional boundaries
- Include appropriate Spring Boot actuator endpoints
- Apply Spring validation for inputs
- Use proper Spring profiles for environment-specific config
- Include comprehensive testing with Spring Test
C# / .NET Prompts
C# Modern Template
SITUATION: Developing [describe component/feature] using C# [version]
CHALLENGE: Implement [specific functionality] with modern C# features and best practices
AUDIENCE: .NET developers working on a [desktop/web/mobile] application
FORMAT:
- Follow C# coding conventions
- Use modern C# features (pattern matching, nullable reference types, etc.)
- Apply proper object-oriented design
- Implement comprehensive exception handling
- Include XML documentation comments
FOUNDATIONS:
- Use LINQ effectively for data operations
- Apply async/await patterns correctly
- Implement proper resource disposal (IDisposable)
- Leverage C# type system features
- Follow .NET security best practices
- Use appropriate collection classes
SPECIFIC REQUIREMENTS:
- Ensure proper error handling
- Implement logging with appropriate level of detail
- Include comprehensive unit tests
- Apply performance best practices
- Implement proper null handling
ASP.NET Core Template
SITUATION: Building [describe feature] with ASP.NET Core [version]
CHALLENGE: Create [specific component/functionality] following ASP.NET Core best practices
AUDIENCE: .NET developers working on a web application or API
FORMAT:
- Follow ASP.NET Core architectural patterns
- Use dependency injection appropriately
- Implement proper MVC/API controller design
- Structure project following clean architecture principles
- Apply appropriate middleware components
FOUNDATIONS:
- Use ASP.NET Core's built-in dependency injection
- Implement proper model validation
- Apply appropriate authorization and authentication
- Use routing effectively
- Implement proper configuration management
- Apply correct HTTP status codes and responses
SPECIFIC REQUIREMENTS:
- Include appropriate action filters
- Implement proper model binding
- Use tag helpers in views (for MVC)
- Apply caching where appropriate
- Include integration tests with TestServer
Ruby Prompts
Ruby General Template
SITUATION: Building [describe feature] with Ruby [version]
CHALLENGE: Implement [specific functionality] following Ruby idioms and best practices
AUDIENCE: Ruby developers of [beginner/intermediate/advanced] skill level
FORMAT:
- Follow Ruby style guidelines (The Ruby Style Guide)
- Use idiomatic Ruby expressions and methods
- Apply functional aspects of Ruby where appropriate
- Include proper error handling
- Add comprehensive documentation
FOUNDATIONS:
- Use Ruby blocks, procs, and lambdas effectively
- Apply Ruby's duck typing appropriately
- Leverage Ruby's metaprogramming when it adds value
- Implement proper exception handling
- Use Ruby's built-in Enumerable methods
SPECIFIC REQUIREMENTS:
- Ensure compatibility with Ruby [version]
- Include comprehensive RSpec tests
- Follow Ruby security best practices
- Implement proper logging
- Apply appropriate design patterns
Ruby on Rails Template
SITUATION: Developing [describe feature] in a Ruby on Rails [version] application
CHALLENGE: Create [specific functionality] following Rails conventions and best practices
AUDIENCE: Rails developers on a team-based web application
FORMAT:
- Follow Rails conventions (CoC principles)
- Use appropriate Rails generators where helpful
- Apply the Rails MVC architecture properly
- Structure code for maintainability and testing
- Include proper documentation
FOUNDATIONS:
- Use ActiveRecord patterns appropriately
- Implement proper validations
- Apply Rails routing conventions
- Use Rails helpers effectively
- Implement proper error handling
- Follow Rails security best practices
SPECIFIC REQUIREMENTS:
- Create appropriate migrations for database changes
- Implement proper authentication/authorization
- Use Rails form helpers appropriately
- Apply N+1 query optimizations
- Include comprehensive tests (model, controller, integration)
Go Prompts
Go Template
SITUATION: Building [describe component/feature] with Go [version]
CHALLENGE: Implement [specific functionality] following Go idioms and best practices
AUDIENCE: Go developers working on a [service/tool/application]
FORMAT:
- Follow official Go code style (gofmt)
- Apply Go's simplicity and readability principles
- Use proper error handling patterns
- Implement appropriate concurrency patterns
- Include comprehensive documentation
FOUNDATIONS:
- Apply Go's composition over inheritance
- Use Go's error handling conventions (return errors)
- Implement proper resource management
- Apply Go's concurrency patterns correctly
- Use appropriate Go packages and standard library
- Structure code following Go project conventions
SPECIFIC REQUIREMENTS:
- Ensure proper error handling and propagation
- Implement appropriate logging
- Include comprehensive tests
- Apply Go performance best practices
- Follow Go security guidelines
PHP Prompts
PHP Modern Template
SITUATION: Developing [describe component/feature] with PHP [version]
CHALLENGE: Implement [specific functionality] using modern PHP features and best practices
AUDIENCE: PHP developers working on a [web application/API/service]
FORMAT:
- Follow PSR coding standards
- Use modern PHP features (type declarations, generators, etc.)
- Implement proper object-oriented design
- Apply namespaces and autoloading
- Include comprehensive error handling
FOUNDATIONS:
- Use PHP's type system effectively
- Apply proper exception handling
- Implement appropriate error logging
- Use PHP's built-in functions where appropriate
- Follow PHP security best practices
SPECIFIC REQUIREMENTS:
- Ensure PHP [version] compatibility
- Use Composer for dependency management
- Include unit tests with PHPUnit
- Apply proper input validation
- Implement secure session management
Laravel Framework Template
SITUATION: Building [describe feature] with Laravel [version]
CHALLENGE: Create [specific functionality] following Laravel best practices
AUDIENCE: Laravel developers working on a web application
FORMAT:
- Follow Laravel coding style and conventions
- Use Laravel's elegant syntax and features
- Apply appropriate design patterns
- Implement proper error handling and logging
- Include comprehensive documentation
FOUNDATIONS:
- Use Laravel's Eloquent ORM correctly
- Implement proper form validation
- Apply Laravel's middleware architecture
- Use blade templates effectively
- Implement proper authentication and authorization
- Follow Laravel's service container patterns
SPECIFIC REQUIREMENTS:
- Create appropriate migrations and models
- Implement proper route definitions
- Use Laravel's form request validation
- Apply queue processing where appropriate
- Include Laravel-specific tests
Mobile Development Prompts
Swift for iOS Template
SITUATION: Developing [describe feature] for an iOS [version] application
CHALLENGE: Create [specific functionality] following Swift and iOS best practices
AUDIENCE: iOS developers working on a mobile application
FORMAT:
- Follow Swift style guidelines
- Use Swift's modern features
- Apply iOS design patterns
- Implement proper error handling
- Include comprehensive documentation
FOUNDATIONS:
- Apply Swift's strong typing effectively
- Use Swift protocols and extensions appropriately
- Implement proper resource management
- Apply iOS UI patterns (MVC, MVVM, etc.)
- Follow Apple's Human Interface Guidelines
- Use Swift's optionals correctly
SPECIFIC REQUIREMENTS:
- Ensure compatibility with iOS [version]
- Apply proper auto layout constraints
- Implement appropriate accessibility features
- Include unit and UI tests
- Optimize for performance and battery life
Kotlin for Android Template
SITUATION: Building [describe feature] for an Android application
CHALLENGE: Implement [specific functionality] following Kotlin and Android best practices
AUDIENCE: Android developers working on a mobile application
FORMAT:
- Follow Kotlin coding conventions
- Use Android architecture components
- Apply appropriate app architecture (MVVM, MVI, etc.)
- Implement proper error handling
- Include comprehensive documentation
FOUNDATIONS:
- Use Kotlin's language features effectively
- Apply coroutines for asynchronous operations
- Implement proper lifecycle management
- Use Android Jetpack libraries appropriately
- Apply material design principles
- Implement proper permissions handling
SPECIFIC REQUIREMENTS:
- Ensure compatibility with Android API level [number]
- Apply appropriate UI state management
- Implement proper background processing
- Include unit and instrumentation tests
- Optimize for performance and battery life
Flutter Cross-Platform Template
SITUATION: Developing [describe feature] with Flutter [version]
CHALLENGE: Create [specific functionality] for a cross-platform mobile application
AUDIENCE: Flutter developers building for iOS and Android
FORMAT:
- Follow Flutter and Dart best practices
- Apply appropriate state management approach
- Implement responsive layouts
- Use proper widget composition
- Include comprehensive error handling
FOUNDATIONS:
- Use Dart's language features effectively
- Apply appropriate Flutter widgets
- Implement proper state management (Provider, Bloc, Riverpod, etc.)
- Use Flutter's layout system correctly
- Follow platform-specific design guidelines where needed
- Apply appropriate animations and transitions
SPECIFIC REQUIREMENTS:
- Ensure cross-platform compatibility
- Implement appropriate platform-specific code where needed
- Apply proper navigation patterns
- Include widget and integration tests
- Optimize for performance on both platforms
Database-Specific Prompts
SQL Database Template
SITUATION: Designing [describe database component] for a [database system]
CHALLENGE: Create [specific database objects/queries] with performance and security in mind
AUDIENCE: Database developers working on a [type of application]
FORMAT:
- Follow SQL best practices and conventions
- Use appropriate data types and constraints
- Implement proper indexing strategy
- Include comprehensive error handling
- Add appropriate comments and documentation
FOUNDATIONS:
- Apply normalization principles appropriately
- Use database-specific features when beneficial
- Implement proper transaction management
- Apply appropriate security measures
- Optimize for query performance
- Use appropriate locking strategies
SPECIFIC REQUIREMENTS:
- Ensure compatibility with [database version]
- Include proper error handling and logging
- Implement appropriate indexing
- Address performance considerations
- Apply proper security measures (injection prevention, least privilege)
MongoDB Template
SITUATION: Designing [describe database component] using MongoDB [version]
CHALLENGE: Create [specific MongoDB implementation] following NoSQL best practices
AUDIENCE: NoSQL database developers working on a [type of application]
FORMAT:
- Follow MongoDB schema design best practices
- Use appropriate document structures
- Implement proper indexing strategy
- Include error handling and validation
- Add comprehensive documentation
FOUNDATIONS:
- Apply denormalization appropriately
- Use MongoDB aggregation framework effectively
- Implement proper validation rules
- Apply appropriate security measures
- Optimize for query performance
- Use proper concurrency handling
SPECIFIC REQUIREMENTS:
- Ensure compatibility with MongoDB [version]
- Include proper error handling and logging
- Implement appropriate indexing strategy
- Address performance considerations
- Apply proper security measures
Best Practices for Language-Specific Prompts
Request Idiomatic Code
Explicitly ask for language-specific idioms and patterns:
Please use:
- Language-specific idioms and patterns
- Built-in features of the language rather than generic implementations
- Standard library functions where appropriate
- Conventional error handling for the language
- Naming conventions specific to the language/framework
Specify Version Compatibility
Be explicit about version requirements:
Ensure compatibility with:
- [Language] version [X.Y] and above
- [Framework] version [A.B]
- [Runtime] version [C.D]
- Avoid features not available in these versions
Request Performance Considerations
Ask for language-specific performance optimizations:
Please implement with these performance considerations:
- Use language-specific optimization techniques
- Apply appropriate data structures for the language
- Consider memory management appropriate to the language
- Implement concurrency using language-specific patterns
- Address known performance pitfalls in this language/framework
Evaluating Language-Specific Results
When evaluating AI-generated language-specific code, consider these questions:
Idiomaticity: Does the code follow language-specific conventions and best practices?
Feature Usage: Does it appropriately use language-specific features and libraries?
Error Handling: Does it implement error handling in the language's typical style?
Performance: Does it use language-optimized approaches where appropriate?
Architecture: Does it follow framework-specific patterns and architecture?
Maintainability: Would an experienced developer in this language find it well-structured?
Example: Contrast Between Languages
Problem: Implement a function to calculate statistics (mean, median, mode) for a list of numbers
Python Implementation
from collections import Counter
from statistics import mean, median
from typing import Dict, List, Tuple, Union
def calculate_statistics(numbers: List[Union[int, float]]) -> Dict[str, Union[float, List[Union[int, float]]]]:
"""
Calculate statistical measures for a list of numbers.
Args:
numbers: A list of integers or floats
Returns:
Dictionary containing the mean, median, and mode(s)
Raises:
ValueError: If the input list is empty
"""
if not numbers:
raise ValueError("Cannot calculate statistics of an empty list")
# Calculate mean
avg = mean(numbers)
# Calculate median
med = median(numbers)
# Calculate mode (most common value(s))
counter = Counter(numbers)
max_frequency = max(counter.values())
modes = [num for num, freq in counter.items() if freq == max_frequency]
return {
"mean": avg,
"median": med,
"mode": modes[0] if len(modes) == 1 else modes
}
JavaScript Implementation
/**
* Calculate statistical measures for an array of numbers
*
* @param {number[]} numbers - Array of numbers to analyze
* @returns {Object} Object containing mean, median, and mode statistics
* @throws {Error} If the input array is empty
*/
function calculateStatistics(numbers) {
if (!numbers || numbers.length === 0) {
throw new Error('Cannot calculate statistics of an empty array');
}
// Calculate mean
const mean = numbers.reduce((sum, num) => sum + num, 0) / numbers.length;
// Calculate median
const sorted = [...numbers].sort((a, b) => a - b);
const middle = Math.floor(sorted.length / 2);
const median = sorted.length % 2 === 0
? (sorted[middle - 1] + sorted[middle]) / 2
: sorted[middle];
// Calculate mode (most common value(s))
const frequency = new Map();
let maxFrequency = 0;
numbers.forEach(num => {
const count = (frequency.get(num) || 0) + 1;
frequency.set(num, count);
maxFrequency = Math.max(maxFrequency, count);
});
const modes = [...frequency.entries()]
.filter(([_, count]) => count === maxFrequency)
.map(([value, _]) => value);
return {
mean,
median,
mode: modes.length === 1 ? modes[0] : modes
};
}
Java Implementation
import java.util.*;
/**
* Utility class for statistical calculations
*/
public class StatisticsCalculator {
/**
* Calculate statistical measures for a list of numbers
*
* @param numbers List of numbers to analyze
* @return Map containing the mean, median, and mode statistics
* @throws IllegalArgumentException if the input list is empty
*/
public static Map<String, Object> calculateStatistics(List<Double> numbers) {
if (numbers == null || numbers.isEmpty()) {
throw new IllegalArgumentException("Cannot calculate statistics of an empty list");
}
Map<String, Object> results = new HashMap<>();
// Calculate mean
double sum = 0;
for (Double num : numbers) {
sum += num;
}
double mean = sum / numbers.size();
results.put("mean", mean);
// Calculate median
List<Double> sortedList = new ArrayList<>(numbers);
Collections.sort(sortedList);
int middle = sortedList.size() / 2;
double median;
if (sortedList.size() % 2 == 0) {
median = (sortedList.get(middle - 1) + sortedList.get(middle)) / 2.0;
} else {
median = sortedList.get(middle);
}
results.put("median", median);
// Calculate mode (most common value(s))
Map<Double, Integer> frequency = new HashMap<>();
int maxFrequency = 0;
for (Double num : numbers) {
int count = frequency.getOrDefault(num, 0) + 1;
frequency.put(num, count);
maxFrequency = Math.max(maxFrequency, count);
}
List<Double> modes = new ArrayList<>();
for (Map.Entry<Double, Integer> entry : frequency.entrySet()) {
if (entry.getValue() == maxFrequency) {
modes.add(entry.getKey());
}
}
results.put("mode", modes.size() == 1 ? modes.get(0) : modes);
return results;
}
}
Conclusion
Language and framework-specific prompts are essential for generating code that not only works but also follows the idioms, patterns, and best practices of the target environment. By tailoring prompts to specific languages and frameworks, you can produce more maintainable, performant, and idiomatic code that integrates seamlessly with existing codebases.
Remember that different languages have different philosophies, paradigms, and conventions. By acknowledging and embracing these differences in your prompts, you can leverage AI assistance to generate code that feels natural to developers experienced in those specific environments.
As you work with language-specific prompts, continue to refine them based on the quality of generated code and evolving best practices in each language ecosystem. The most effective prompts evolve alongside the languages and frameworks they target.
Last updated