Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31211

Re: JSlint finds for loops intolerable

Path csiph.com!aioe.org!.POSTED!not-for-mail
From emf <emfril@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: JSlint finds for loops intolerable
Date Mon, 29 Aug 2016 22:35:47 -0400
Organization Aioe.org NNTP Server
Lines 82
Message-ID <nq2re1$1rua$1@gioia.aioe.org> (permalink)
References <npug18$166s$1@gioia.aioe.org> <npuldh$q9l$1@solani.org>
NNTP-Posting-Host IBbi8JnyfVu0+hwxyhSZwg.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.javascript:31211

Show key headers only | View raw


On 2016-08-28 08:28, Christoph M. Becker wrote:
> On 28.08.2016 at 12:56, emf wrote:
>
>> In the current JSLint help webpage (http://jslint.com/help.html) it now
>> says:
>>
>> "Tolerate for statement:
>> true if the for statement should be allowed
>> It is almost always better to use the array methods instead."
>
> JSLint, as well as its author, are highly opinitated. :-)

For the time being I've been following its direction, though I'd prefer 
that it wouldn't change that often.
>
>> Getting rid of the for loops is a big change. Reflecting on it, however,
>> the for loop is an awkward construction -- it's just something you learn
>> as a matter of fact when you begin and that time on you take it for
>> granted. Instead of
>>
>> for (var i = 0; i < 10; i += 1) {
>>     ...
>> }
>>
>> the while loop does seem more straightforward:
>>
>> var i = 0;
>> while (i < 10) {
>>     ...
>>     i += 1;
>> }
>
> I would prefer the `while` only, if you can count down, e.g.
>
>   var i = 10;
>   while (--i) {
>       ...
>   }
s
Interesting, however JSLint doesn't tolerate ++ and --. Following its 
trajectory, I wouldn't be surprised if at sone point it will stop 
tolerating += and -= also.

>> After stopping using for loops, I can imagine a time when I won't be
>> able to understand why I once almost always preferred to use them.
>
> Perhaps because they clearly signal a loop with N iterations?

No. from my recollections, it's because when learning programming we 
were taught the for loop first -- maybe because it was the most 
complicated -- and only after we had mastered it, as an afterthought, we 
were taught that there were also the while and the do-while loops.

>> I do not understand, however, the comment about array methods. I seldom
>> find use for them. Can someone explain what Crawford implies??
>
> Instead of looping with `for` or `while` over all elements of an array,
> you can instead do:
>
>   myArray.forEach(function(el) {
>       ...
>   });
>
> Once you get the hang of using Array.prototype.forEach(), you'll
> probably find many places where a more specific array method is more
> appropriate (for instance, .filter() and map()), and these can simplify
> the code (even more).

I'll have to look into this. In the meantime, I'll get used to using the 
while loop.

> Note that this programming style is often referred to as applicative or
> functional programming.  You may consider to learn about it (I can
> recommend <https://drboolean.gitbooks.io/mostly-adequate-guide/content/>).

I downloaded the kindle version of the book. Thanks,

Eustace

-- 
Natal Transits Calculator
http://emf.neocities.org/nt/nataltransits.html

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

JSlint finds for loops intolerable emf <emfril@gmail.com> - 2016-08-28 06:56 -0400
  Re: JSlint finds for loops intolerable "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-08-28 14:28 +0200
    Re: JSlint finds for loops intolerable emf <emfril@gmail.com> - 2016-08-29 22:35 -0400
    Re: JSlint finds for loops intolerable Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-30 12:11 +0200
      Re: JSlint finds for loops intolerable "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-09-03 20:54 +0200
      Re: JSlint finds for loops intolerable Scott Sauyet <scott@sauyet.com> - 2016-09-03 23:03 +0000
    Re: JSlint finds for loops intolerable Scott Sauyet <scott@sauyet.com> - 2016-09-03 22:47 +0000
  Re: JSlint finds for loops intolerable Lewis Perin <perin@panix.com> - 2016-08-28 16:50 -0400
    Re: JSlint finds for loops intolerable Lewis Perin <perin@panix.com> - 2016-08-28 18:49 -0400
      Re: JSlint finds for loops intolerable Lewis Perin <perin@panix.com> - 2016-08-28 19:13 -0400
  Re: JSlint finds for loops intolerable $Bill <news@todbe.com> - 2016-08-28 14:59 -0700

csiph-web