Gemini Prompts for Variable Naming: 5 Ready-to-Use Ideas

You open a file you wrote last month and stop at a variable called temp2. You know what it does, but only after reading twenty lines around it. Good names save that minute every time anyone reads the file, including future you. These five Gemini prompts handle the naming work: fill in the table, run the prompts, and let the code explain itself.

Before you start: the variables

[Variable] What to fill in
[language] The language or framework, such as Python, TypeScript, or Go.
[code block] The exact snippet whose names you want to fix.
[style guide] Your team’s naming rules, such as camelCase for variables and PascalCase for types.
[data type] What the value holds, so the name can hint at it without being noisy.
[scope] How far the name travels: local loop, module, or public API.

The prompts

1. Rename for clarity

Rename the variables in this [language] code so the names explain themselves: [code block]. Follow [style guide]. Keep names short but specific, and return the full code with only the names changed. List each rename as old name to new name.

What it does: Replaces vague names with ones a reader can trust without scrolling for context.

How to use: replace [language], [code block], and [style guide]; keep the rest as is.

2. Name a new concept

I am adding a value that holds [data type] and means [what it represents]. Suggest 5 names that follow [style guide] and read well at [scope] level. For each, say in one line why it works or where it could confuse a reader.

What it does: Gives you several solid options for the hardest part of naming — the first name.

How to use: replace [data type], [what it represents], [style guide], and [scope]; keep the rest as is.

3. Apply one convention everywhere

Check this code against this naming convention: [style guide]. Here is the code: [code block]. Flag every name that breaks the rule and give the corrected name. Group the fixes by file or section so I can apply them in order.

What it does: Makes naming consistent across a file without a slow manual scan.

How to use: replace [style guide] and [code block]; keep the rest as is.

4. Expand unclear abbreviations

This code uses abbreviations and single letters: [code block]. Spell out every abbreviation that a new teammate would not recognize, keep the widely known ones, and explain in one line why you kept each one you left alone.

What it does: Removes the shorthand that only the original author understood.

How to use: paste the code into [code block]; keep the rest as is.

5. Audit names across a file

Review the names in this file for consistency and clarity: [code block]. List any name that is misleading, inconsistent with the others, or too similar to another name. For each, give a better option and one line of reasoning.

What it does: Catches the near-duplicate names that cause copy-paste bugs.

How to use: paste the whole file into [code block]; keep the rest as is.

A quick worked example

Take prompt 1. Suppose you paste this Python loop:

def calc(d, r):
    t = 0
    for x in d:
        t += x * r
    return t

With [language] set to Python and [style guide] set to “snake_case for variables, descriptive names,” the model returns:

def calculate_total(line_items, tax_rate):
    total = 0
    for item in line_items:
        total += item * tax_rate
    return total

Nothing about the logic changed. The next reader now understands the function from its names alone, which is the whole point.

These prompts are free to use. Copy them, tweak the [variables], ship something.

Keep going

Leave a Comment