lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [lmi-commits] master 2038991 15/33: Improve concinnity


From: Vadim Zeitlin
Subject: Re: [lmi] [lmi-commits] master 2038991 15/33: Improve concinnity
Date: Thu, 13 May 2021 20:45:00 +0200

On Thu, 13 May 2021 18:15:34 +0000 Greg Chicares <gchicares@sbcglobal.net> 
wrote:

GC> If we could pick a good single-letter name other than 'i'
GC> for all these not-an-iterators, I'd be happy to change
GC> them all. I'd suggest 'q' because it's not often otherwise
GC> used.

 Why should we use an intentionally meaningless letter for the loop
variables? If you really wanted to do this, you already use "z" for a
similar purpose, so it would seem to be a natural choice here too, but why
would you want to do it in the first place? Generally speaking, the loop
variable is not mute or unimportant, it can be used multiple times and it
definitely can be helpful to understand what does it refer to.

GC> It took me a while to guess that "directory entry" was meant.
GC> If it were this:
GC>   for(auto const& q : fs::directory_iterator(path))
GC> then it would speak more clearly to me: 'q' would mean
GC>   "the thing we're iterating with"

 But this is hardly useful if you don't know what this thing is. Iterating
over characters is different from iterating over doubles is different from
iterating over vectors of structs.

GC> and it could be the same in all such loops. Not
GC>   "the directory entry we're iterating with"
GC> in one place, and
GC>   "the string we're iterating with"
GC> elsewhere: just "the thing", like the pronoun "it" (but 'it'
GC> isn't a good name here because it suggests "iterator", and
GC> this is a not-an-iterator).

 "it" is not a good name because it's meaningless. This can be unimportant
for very simple loops, but it can also be important for the more complex
ones.

GC> I tend to dislike names with only two characters.

 OK, let's make it longer. "directory_entry" might be too long, but just
"entry" would be still clear enough in the context and well worth it.

GC> But consider these two examples from 'group_values.cpp':
GC> 
GC>     for(auto const& i : cells)
GC>     for(auto const& ip : cells)
GC> 
GC> In the first one, 'i' (or, e.g., 'q' if you will) has
GC> too few characters to mean anything, so it must mean
GC> the only thing it can mean: "this thing". In the second,
GC> what's 'ip'? Maybe it was originally "Input Parameters".
GC> How can anyone guess? Why should anyone have to guess?
GC> Search engines would say "Intellectual Property" or
GC> "Internet Protocol". The one-character name is much
GC> stronger.

 I don't know how do you determine the name strength, but for me it's
mostly completely meaningless. It should have been called "input" in both
places because this is what it is (alternatively, it probably could be
called "cell" too, if we call a collection of Inputs "cells").

 For me there is really no question at all about which name is better
between "i" and "entry", or "i" and "input" and I have to admit that I
don't really understand what possible arguments could there be in favour of
it. The important thing is not that this variable contains the current
loop value (why would this be important?), but _what_ it is.

 I don't think what I'm writing is very convincing, as I don't give any
real arguments neither, as I have trouble to marshal them just because this
seems to obvious to me. But let me at least register the alternative point
of view: if "de" is too short (I thought it would be clear from the
context, but I was clearly wrong about this), it should be made longer,
but not replaced with a meaningless shortest possible name.

VZ

Attachment: pgpdaFbvY19R_.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]