Let Copilot Help You Name Things
Randy Pagels demonstrates how GitHub Copilot can help developers generate more effective names for code elements, making software easier to maintain and understand.
Let Copilot Help You Name Things
Posted on Apr 25, 2025 by Randy Pagels
Naming things in programming—from functions and classes to variables and fields—is notoriously challenging. This post explores practical ways to use GitHub Copilot’s AI capabilities to generate clear, descriptive names and maintain consistent coding standards.
Why Naming Matters
Poorly named code can become hard to maintain, difficult to read, and prone to bugs. Yet, coming up with the perfect name can interrupt your development flow. GitHub Copilot provides context-aware suggestions, making it easier to pick names that accurately describe what your code does.
Copilot in Action: Practical Steps
1. Copilot Chat: Ask for a Better Name
-
You can prompt Copilot with comments in your code, such as:
// Suggest a more descriptive name for this function that calculates discount based on user role and cart total
-
Copilot will analyze the code context and offer relevant name suggestions.
2. Edit Mode: Inline Rename Prompt
-
Highlight a variable or function, and leave an inline comment like:
# Rename this variable to better reflect what it represents
-
Trigger Copilot Agent Mode for quick, automated renaming.
3. Agent Mode: Naming Conventions at Scale
- When refactoring larger codebases, Copilot can generate consistent variable and method names across multiple files or controllers, such as applying CRUD naming patterns.
Example Prompts to Use
# Rename this class to better describe what it models
# What’s a better name for this loop counter?
# Suggest field names for a form collecting user contact details
// Rename this test to clearly describe what it's testing
Quick Takeaway
Improving naming doesn’t need to slow you down. With GitHub Copilot, you can quickly generate clear, maintainable names, making your codebase easier to read and update.
This post appeared first on “Randy Pagels’s Blog”. Read the entire article here