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


Groups > comp.lang.javascript > #18043

Re: Request for opinions on my newbie approach

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From "Leonardo Azpurua" <leonardo@exmvps.org>
Newsgroups comp.lang.javascript
Subject Re: Request for opinions on my newbie approach
Date Wed, 9 Jan 2013 18:10:10 -0430
Organization A noiseless patient Spider
Lines 33
Message-ID <kckrav$41u$1@dont-email.me> (permalink)
References <kcilrc$vt8$1@dont-email.me> <10136443.OnBuAidq6I@PointedEars.de> <a2hre85m1aojpu1l2a46uqbklvnhq7ih3h@4ax.com>
Injection-Date Wed, 9 Jan 2013 22:35:11 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="de2878c18c27ea00a51224844a34e6d4"; logging-data="4158"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ETTPJt+CpmEVKf+IJcgkhzvTqRHRJPm8="
X-MimeOLE Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646 Format=Flowed; Original
X-Newsreader Microsoft Outlook Express 6.00.2900.5512
Cancel-Lock sha1:b/LHETDGF+aO1y9hM7VVdwODAic=
X-Priority 3
X-MSMail-Priority Normal
Xref csiph.com comp.lang.javascript:18043

Show key headers only | View raw


"Jim T." <x@y.z> escribió en el mensaje 
news:a2hre85m1aojpu1l2a46uqbklvnhq7ih3h@4ax.com...
> On Wed, 09 Jan 2013 04:31:58 +0100, Thomas 'PointedEars' Lahn
>>>     for (var i = 0; i < f.elements.length; i++)
>>
>>      for (var i = 0, len = f.elements.length; i < len; ++i)
>
> Why? Because it's faster? First, modern JS interpreters will probably
> already do this optimization. Second, unless the form has a million
> elements it will make no noticeable difference. Cleaner code is better
> than pointless "optimization".

Hi,

In this particular case, Thomas is absolutely right.

Good style -hence good code- comes from good habits.

And good habits come from the strict observance of best coding rules: unless 
a function value may change during the loop execution, avoid using the 
function as a limit for the loop.

Thomas suggestion is an improvement independently of the context. My 
original code may be fine in the given context, but is bad code.

And bad code must be corrected.

It is not a trivial optimization, but an important correction of the style.

--

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


Thread

Request for opinions on my newbie approach "Leonardo Azpurua" <leonardo@exmvps.org> - 2013-01-08 22:24 -0430
  Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 04:31 +0100
    Re: Request for opinions on my newbie approach "Leonardo Azpurua" <leonardo@exmvps.org> - 2013-01-08 23:34 -0430
      Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 05:14 +0100
    Re: Request for opinions on my newbie approach Jim T. <x@y.z> - 2013-01-09 14:32 -0500
      Re: Request for opinions on my newbie approach Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-09 20:41 +0100
        Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 21:03 +0100
        Re: Request for opinions on my newbie approach Jim T. <x@y.z> - 2013-01-09 15:11 -0500
        Re: Request for opinions on my newbie approach Luc Yen <luc@goal.tw> - 2013-01-09 14:38 -0800
      Re: Request for opinions on my newbie approach "Leonardo Azpurua" <leonardo@exmvps.org> - 2013-01-09 18:10 -0430
        Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-10 01:36 +0100

csiph-web