[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:

  1. Idiomatic Code: Generate code that follows language-specific conventions and best practices

  2. Optimized Solutions: Leverage language-specific features for more efficient implementations

  3. Framework Alignment: Properly utilize framework-specific patterns and architecture

  4. Better Error Handling: Implement language-appropriate error handling strategies

  5. 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

FastAPI Template

JavaScript/TypeScript Prompts

JavaScript Modern Template

TypeScript Template

React Framework Template

Angular Framework Template

Java Prompts

Java Modern Template

Spring Boot Framework Template

C# / .NET Prompts

C# Modern Template

ASP.NET Core Template

Ruby Prompts

Ruby General Template

Ruby on Rails Template

Go Prompts

Go Template

PHP Prompts

PHP Modern Template

Laravel Framework Template

Mobile Development Prompts

Swift for iOS Template

Kotlin for Android Template

Flutter Cross-Platform Template

Database-Specific Prompts

SQL Database Template

MongoDB Template

Best Practices for Language-Specific Prompts

Request Idiomatic Code

Explicitly ask for language-specific idioms and patterns:

Specify Version Compatibility

Be explicit about version requirements:

Request Performance Considerations

Ask for language-specific performance optimizations:

Evaluating Language-Specific Results

When evaluating AI-generated language-specific code, consider these questions:

  1. Idiomaticity: Does the code follow language-specific conventions and best practices?

  2. Feature Usage: Does it appropriately use language-specific features and libraries?

  3. Error Handling: Does it implement error handling in the language's typical style?

  4. Performance: Does it use language-optimized approaches where appropriate?

  5. Architecture: Does it follow framework-specific patterns and architecture?

  6. 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

JavaScript Implementation

Java Implementation

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