Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!not-for-mail From: Lewis Perin Newsgroups: comp.lang.javascript Subject: Re: JSlint finds for loops intolerable Date: Sun, 28 Aug 2016 16:50:50 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 51 Message-ID: References: NNTP-Posting-Host: panix1.panix.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: reader2.panix.com 1472417451 27461 166.84.1.1 (28 Aug 2016 20:50:51 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 28 Aug 2016 20:50:51 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (berkeley-unix) Cancel-Lock: sha1:CCNfTkJfqsOXYgLmVp0PmKs20uI= Xref: csiph.com comp.lang.javascript:31195 ram@zedat.fu-berlin.de (Stefan Ram) writes: >emf writes: >>for (var i = 0; i < 10; i += 1) { >> ... >>} >>var i = 0; >>while (i < 10) { >> ... >> i += 1; >>} > > When one compares this, one can see: > > - The for loop is a Statement. > > - The corresponding sequence that uses > »while« is a StatementList with /two/ > StatementListItems. > > So the corresponding statement would be > >{ var i = 0; while( i < 10 ){ ... ++i; }} > > . But »...« could be quite long, so it might > be hard to see »++i« at the same time as the > start of the loop. > > The for loop-head is one »chunk« in the brain. > The control of the while loop is distributed > in two, or possibly three, different places, > it cannot be seen as a single idiom by the brain. > > While theoretically the while loop /is/ simpler, > it might be too low-level. It seems that the for > loop comes more naturally to humans. Especially > for counting loops and similar loops. > > Due to hoisting »for( var« might be misleeding, > so I deem »for( let« more natural. > I’m generally sympathetic to the idea that one criterion for judging programs is how easy they are to reason about. But there’s often a glibness about this when it isn’t clear who is doing the reasoning: a person or a computer program? /Lew --- Lew Perin / perin@acm.org http://babelcarp.org