3 ms·
Argument in favour of short variable names; 1. They're quicker to type. Arguments against them; 1. You can tell what they mean by reading them. 2. Other peop
by onion2k 11y ago
Argument in favour of short variable names;
1. They're quicker to type.
Arguments against them;
1. You can tell what they mean by reading them.
2. Other people can tell what they mean by reading them.
3. Tab completion is a thing.
It's a no brainer.
- SlipperySlope 11y agoWhen I began programming in 1968, Fortran IV offered upper case variable names up to 6 characters long. Often the first character was used to implicitly define the type, e.g. a variable denoting an integer began with "I". The convention of using a variable named "i" to denote an loop index took hold with Fortran. In 1973, I began programming in COBOL, which was again upper case only with regard to variable names but allowed 30 characters, often consisting of domain relevant words separated by dashes, e.g. "INVOICE-NUMBER". This was so much better than FORTRAN. The theme of COBOL was to have a computer language that read like English. For example, "DIVIDE ACCOUNT-INCREASE BY DAYS-IN-MONTH GIVING AVERAGE-INCREASE-PER-DAY." When I began programming in Smalltalk and Java in the 1990's, the variable names could be very long, and I used the Camel case style of composing names without separation characters, e.g "invoiceNumber". Because I have a strong interest in automatic programming, I try to write code as it would be written by an AI. I favor variable names in Java that mirror the object type, e.g. "stringBuilder", "outputStream", "propertyEditorManager". The rationale is that if the AI creates the variable names, there is a simple rule for forming them, and the length is no bother to the human who does not actually type them, but simply reads them.