News for hackers. Stuff that matters.
Re:Why we need a book about naming by anilakar on Thursday February 13, 2020 @05:16AM (#22316606)
This has probably been said a dozen times already, but short symbol names are indeed acceptable in various situations, including but not limited to:

- Where they are actually correct, such as dimensions (x, y, z) or vectors (j, k, l, u, v, w).

- Other mathematical symbols (N, M, e, t). Maths is also a special case in which I'm personally willing to do away with usual variable naming conventions, for example when translating formulas from a scientific paper into program code.

- Very short code, e.g. lambdas (lambda x: x2), list comprehensions ([p.title for p in posts]) or simple loops.

If you look at SQLite, you'll notice that most variable and struct field names are short and cryptic, and that library is still considered a high-quality piece of code.

Regardless, I don't understand all the downvotes you're getting.

Re:Why we need a book about naming by vbezhenar on Thursday February 13, 2020 @10:40AM (#22318550)
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;
Re:Why we need a book about naming by viklove on Thursday February 13, 2020 @12:06PM (#22319324)
Naming 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');
Re:Why we need a book about naming by vbezhenar on Thursday February 13, 2020 @04:14PM (#22321492)
How would you name an abstract string without any implied meaning?
Re:Why we need a book about naming by viklove on Thursday February 13, 2020 @06:37PM (#22322489)
If 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.
Re:Why we need a book about naming by kbob on Thursday February 13, 2020 @07:38AM (#22317241)
> list comprehensions

Yes. Very much yes. My personal rule is to _always_ use single-letter names for Python comprehension indices, because line length is the biggest enemy of readability there.

Re:Why we need a book about naming by hhjinks on Thursday February 13, 2020 @05:31PM (#22322079)
In my experience, one-character variables are serviceable, even preferable, when you're piping data, like Streams in java, or all the equivalent functions in rust. So long as the starting input's type is clear, the "capturing" variable can be just the first letter of the type.