lmi
[Top][All Lists]
Advanced

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

Re: [lmi] [PATCH] C++ m11n: range-based for loops


From: Vadim Zeitlin
Subject: Re: [lmi] [PATCH] C++ m11n: range-based for loops
Date: Fri, 20 Jan 2017 23:16:00 +0100

On Fri, 20 Jan 2017 21:49:24 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2017-01-20 14:24, Vadim Zeitlin wrote:
GC> > On Thu, 19 Jan 2017 23:04:02 +0000 Greg Chicares <address@hidden> wrote:
GC> > 
GC> > GC> I'm done with
GC> > GC>   
https://github.com/vadz/lmi/pull/52/commits/d1fd3ae2e222c6d7a9edd1c9124ef2935e2918a5
GC> > GC> and have pushed the final changes.
GC> [...]
GC> >  One small thing I'm still not completely satisfied about (I have a real
GC> > lack of talent for unconditional happiness, as you might have noticed) is
GC> 
GC> I think of it as a positive talent to call a time-out when something
GC> bothers you.
GC> 
GC> > this idea that we shouldn't be using "for(auto& foo : foos)" because "foo"
GC> > and "foos" names are too close. IMHO this is the most natural way of 
naming
GC> > things (supposing that you use something a bit more descriptive instead of
GC> > a literal "foo")
...
GC> As I'm sure we've discussed before, I also have a hard-coded
GC> register named 'z'
...
GC> A useful incidental benefit is that I can copy and paste code
GC> written in terms of 'z' between files or functions that use 'z'.
GC> The same goes for 'i'.

 Without going into details, I think the arguments you give in favour of
using "z" and "i" are exactly the same as the ones used to justify the
existence of "$_" special variable in Perl (although in the latter case,
it's even more magical and there are also some compatibility
considerations).

 And the conclusion, then, ought to be the same too: while "$_" is known to
make short snippets of code using it more readable, it makes anything more
than a few lines long much less clear. So I think it could be fine to use
"i" for very short loops. But I'd still use a more readable variable name,
even if it's something close to the name of another variable, for anything
longer than 2-3 lines.

 So taking just this into account, "i" would be good in some cases. However
if we also add the consideration of consistency, then it should be never
used in range for loops at all, as it shouldn't be used in all of them. And
I think it would be better to be consistent here. But, at the end, it's a
style choice to make.

 Regards,
VZ


reply via email to

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