AI readable naming convention #
The AI readable naming convention focuses on the way we name variables and functions in our code to make them more readable by AI tools like GitHub Copilot. By avoiding generic and common programming names and embracing specific, descriptive names, we create code that both human developers and AI models which powers Copilot, can easily comprehend.
For example, an engineer creating a library system may use generic words such as “dictionary”, “library”, and “stack” for system variable names and function names. But what if the real type of the variable named “dictionaries” was an array? This is just an example, but GitHub Copilot may give the wrong answer when these things pile up. If you need to provide more context, it’s a good idea to type hint or use comments to add context.
By following this pattern, we enhance the effectiveness of GitHub Copilot, leading to more accurate suggestions and increased developers’ velocity.
Here are three examples that illustrate how different naming conventions can impact the clarity and accuracy of the code:
# This may confuse whether "dictionary" refers to a book or a data type dictionary =
Better Naming with Comments:
# sample list of dictionaries in the library, like "Oxford" and "Cambridge" library_dictionaries = ["Merriam-Webster", "Oxford", "Cambridge"]
Specific Naming with Type Hinting:
from typing import List # A clear and specific variable name with type hinting list_of_dictionaries_in_library: List[str] = ["Merriam-Webster", "Oxford", "Cambridge"]
- Exercise 1: Review your current codebase and identify variables or functions that may be named in a non-descriptive way. Try to rename them following the AI readable naming convention pattern.
- Exercise 2: Experiment with using GitHub Copilot with the new naming pattern, and compare the suggestions and accuracy before and after the change.
- Exercise 3: Write a new piece of code with these naming conventions in mind, and observe how Copilot responds to the code as you write it.
- Exercise 4: Create a naming convention guideline for your team, focusing on AI readability, and integrate it into your team’s coding standards.
- Exercise 5: Encourage the team to use these naming conventions and observe the impact on overall code readability and GitHub Copilot effectiveness over time.
Checklist for Further Learning #
- How can I make my code more readable to both human developers and AI models?
- Are there any specific cases where this naming pattern may not apply or be counterproductive?