How Long Should Variable Names Be? Data From 18,375 Names in Code

The short answer: long enough to read as words, and in proportion to how far the name travels. We counted 18,375 names in 1,200 code snippets across eight languages. The median name as you type it is 5 characters, but the median distinct name is 8, because short names like i and x repeat while long ones are written once. Research finds full words beat single letters and abbreviations for comprehension, so lean toward words everywhere except a few well-known one-letter roles.
Key Findings
- •
The median name as typed is 5 characters; the median distinct name is 8. 84% of names are a single word, and only 2.1% have three or more.
- •
14.8% of names typed are single letters. The most common:
x,T,a,iandb. - •
PHP and Java use the longest names (8.5 and 8.1 characters per distinct name). C uses the shortest (6.1) and the most single letters (23.9%).
- •
Names are 50.5% of every character typed in code, outside strings and comments.
- •
Full words help. In a 2017 study, developers found bugs about 19% faster in code with full-word names than with letters or abbreviations.
Source: TurboType analysis of 18,375 name occurrences (3,385 distinct names) in 1,200 code snippets, October 2026. Method below.
1. How Long Are Variable Names in Real Code?
Style guides argue about name length in the abstract. We counted instead. We took every name in 1,200 snippets from our practice library across eight languages, after removing strings, comments and reserved keywords, and measured each one.
There are two honest answers, and the difference between them is the most useful thing in this post. Counted as you type them, names are short: the median is 5 characters and the most common length is 4. Counted once each, they are longer: the 3,385 distinct names have a median of 8 characters.
The gap exists because short names repeat. A loop counter called i is typed five times in five lines. A function called handleUnexpectedException is declared once and called a handful of times. So most of what your fingers type is short, even in a codebase full of descriptive names.
Most names are also single words: 84% of occurrences. Names like value, name and data carry a lot of code, and only 2.1% of names typed have three words or more.
2. Which Language Uses the Longest Names?
| Language | Distinct name, avg | Name as typed, avg | Single letters | 15+ characters |
|---|---|---|---|---|
| PHP | 8.5 | 6.4 | 7.0% | 5.0% |
| Java | 8.1 | 6.4 | 9.5% | 4.8% |
| Python | 7.2 | 5.4 | 9.8% | 1.2% |
| TypeScript | 7.0 | 5.3 | 17.3% | 1.4% |
| JavaScript | 7.0 | 5.7 | 10.5% | 2.9% |
| C++ | 6.3 | 4.5 | 16.5% | 0.5% |
| Rust | 6.2 | 4.6 | 22.1% | 0.5% |
| C | 6.1 | 4.2 | 23.9% | 0.1% |
The languages fall into two camps. PHP and Java use the longest names, and about one name in twenty they type is 15 characters or more. That is partly culture and partly the standard libraries: IllegalArgumentException and date_default_timezone_set are names you cannot shorten.
C, Rust and C++ use the shortest, with the most single letters, and each for its own reason. C leads at 23.9% of names typed, mostly loop counters (i and j) and short parameters (a, n, b). Rust's are mostly x and y, in closures and coordinates. TypeScript's are generics: T alone appears 171 times in our TypeScript snippets.
The longest names we found were almost all framework or library names: newVirtualThreadPerTaskExecutor (31 characters, Java), WebSecurityConfigurerAdapter and TransactionalEventListener (Spring), and PHP's session_set_cookie_params. The names you choose yourself are usually shorter than the names you call.
3. Are Single-Letter Variable Names Bad?
14.8% of every name typed in our sample was a single letter. The most common were x (326), T (316), a (291), i (232), b (220), n (153), y (147), v (128). Almost every one of them follows a convention:
- •
i,j: loop indices. - •
x,y,n: coordinates, maths and counts. - •
T,K,V: generic type parameters. - •
a,b: the two sides of a comparison or a small pure function such asadd(a, b). - •
e: an exception or an event.
Those are readable because every programmer learns them. The trouble starts when a single letter takes a role with no convention: d for a dictionary of users, r for a response, t for a timeout. The reader has to go and find out what it means.
Robert C. Martin's Clean Code puts the rule simply: "The length of a name should correspond to the size of its scope." A letter is fine for a variable that lives for three lines. It is a problem for one that lives for three hundred.
4. What Does the Research Say About Name Length?
- •
A 2017 study by Hofmeister, Siegmund and Holt asked 72 professional C# developers to find bugs in code that used full words, abbreviations or single letters. With full words they were about 19% faster. Letters and abbreviations were no different from each other.
- •
An earlier study by Lawrie and colleagues, with more than 100 programmers, found full words gave the best comprehension, but often not significantly better than abbreviations. Well-chosen abbreviations were easier to remember.
- •
A review by Greg Wilson notes that the 19% gap is fairly small and other studies found little difference.
So the evidence leans toward words without making abbreviations a sin. A widely understood abbreviation like id, url or config costs little. An invented one like usrMgrCtx costs every reader a moment.
5. Do Long Names Slow Down Typing?
Names matter for typing because there are so many of them. Outside strings and comments, names are 50.5% of all characters typed in our sample. Every extra character in a name you type often is a real cost.
But most long names are not typed often, and when they are, autocomplete types them. We modelled the simplest case: type a name in full the first time it appears in a snippet, then type three letters and accept the suggestion. Even that conservative model saves 9.2% of name keystrokes, and in a real project, where names repeat across files and library names complete from the first letter, the saving is far larger.
The practical upshot: the typing cost of a descriptive name is paid once, and the reading benefit is collected every time someone opens the file. Where typing does matter is the symbols around the names. Our camelCase vs snake_case analysis found that underscores add 10% to the cost of multi-word names.
6. How Long Should a Variable Name Be?
Put the data and the research together and you get a simple guide. Match the length to the job:
| What you are naming | Typical length | Examples |
|---|---|---|
| Index in a short loop | One letter | i, j |
| Coordinates and maths | One letter | x, y, n |
| Generic type parameter | One capital | T, K, V |
| Lambda used once | A letter or one word | x => x * 2, item |
| Local variable | One or two words | total, retryCount |
| Function or method | Verb plus noun, two or three words | parseConfig, send_email |
| Class or type | A noun or noun phrase | Invoice, HttpClient |
| Boolean | A question: is, has, can | isActive, has_errors |
| Constant | Full words, no abbreviations | MAX_RETRIES |
Two rules cover most of it. Scale length to scope: the further a name travels, the more it needs to say. And prefer words to invented abbreviations: the few seconds a longer name costs to type are saved many times over when it is read.
7. Method and Limits
We analysed the 1,200 snippets in TurboType's Python, JavaScript, TypeScript, Java, C, C++, PHP and Rust tracks, 150 each and 191,711 non-space characters. HTML & CSS and the symbol-drill track were left out. String literals and comments were removed, then every identifier was collected and each language's reserved keywords were excluded. Names from libraries and frameworks are included, because you type them too. A name occurrence is one appearance in the code; a distinct name counts each spelling once.
Limits. These are practice snippets, not complete projects. Short examples favour short names such as a, b and x, so full codebases probably have somewhat longer names and fewer single letters. The autocomplete model is deliberately simple.
8. Frequently Asked Questions
How long should a variable name be?
Long enough to read as words, and in proportion to how far it travels. In 18,375 names from 1,200 code snippets, the median name as typed was 5 characters and the median distinct name was 8. Research found full-word names helped developers find bugs about 19% faster than single letters or abbreviations.
Are single-letter variable names bad?
Not always. Conventional ones such as i in a loop, x and y for coordinates and T for a generic type are widely understood. Outside those roles, a 2017 study found single letters were as slow to work with as abbreviations, and both were slower than full words. Single letters made up 14.8% of the names typed in our sample.
Which programming language has the longest variable names?
In our sample, PHP and Java: their distinct names average 8.5 and 8.1 characters. C has the shortest at 6.1, and also the most single-letter names, at 23.9% of every name typed.
Do long variable names slow down typing?
Slightly, and less than you might think. Names are about half of all characters typed in code, but most long names are typed in full only once; after that autocomplete finishes them. Even a conservative model that only counts repeats within one snippet saves 9.2% of name keystrokes.
What are the most common variable names?
After namespaces such as std, the most-typed names in our sample were x, T, value, a, i, b, name and data.
Next Steps:
- Look at the last function you wrote and check that every single-letter name has a conventional role.
- Rename one invented abbreviation to full words and see whether the next reader asks about it.
- Take the 60-second coding typing test to see how fast you type real names and the symbols between them.
Related Resources:
The keystroke cost of each naming style.
All 32 symbols, named and counted.
QWERTY, Dvorak, Colemak and Workman on code.
Every keystroke counted, by finger and row.
