4 ms·
IMO short names are perfectly acceptable and even preferable as a local variable names withing short functions, when context is obvious and everything fits onto
by vbezhenar 7y ago
IMO short names are perfectly acceptable and even preferable as a local variable names withing short functions, when context is obvious and everything fits onto one screen. I would prefer
for (int i = 0, len = string.length(); i <= len; i++) {
char c = string.charAt(i);
if (c == '\t') {
return true;
}
}
return false;
rather than something like
boolean tabFound = false;
int stringLength = string.length();
for (int characterIndex = 0; characterIndex <= stringLength; characterIndex++) {
char character = string.charAt(characterIndex);
if (character == '\t') {
tabFound = true;
}
}
return tabFound;
- viklove 7y agoNaming a variable solely after its type is never particularly useful. A name like `currentChar` would probably enhance readability. Of course if your code is just 2 lines long, `c` works just fine (that's not usually the case though). You should probably abstract away some of that logic though (and `string` isn't a great variable name either): boolean tabFound = includes(line, '\t');
- vbezhenar 7y agoHow would you name an abstract string without any implied meaning?
- viklove 7y agoIf the functionality you're writing is truly that abstract, an abstract variable name is fine. Your example didn't include the method signature though, so I assumed it was a part of some larger (concrete) code block.
- deleted 7y ago[deleted]