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


Groups > comp.lang.javascript > #8325

Re: Difference between findPos("divThis") and findPos(divThis)

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From "J.R." <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: Difference between findPos("divThis") and findPos(divThis)
Date Mon, 14 Nov 2011 15:07:54 -0200
Organization Aioe.org NNTP Server
Lines 153
Message-ID <j9rhta$etf$1@speranza.aioe.org> (permalink)
References <j9olie$dsd$1@dont-email.me> <4775241.ypaU67uLZW@PointedEars.de> <j9p403$e80$1@dont-email.me> <2394720.ArG6xLiZAS@PointedEars.de> <j9p7t8$98q$1@dont-email.me> <j9pas5$ah2$1@speranza.aioe.org> <j9pb43$ah2$2@speranza.aioe.org> <j9pf87$rka$1@dont-email.me> <j9phhk$s3i$1@speranza.aioe.org> <4ec07ef1$0$28711$a8266bb1@newsreader.readnews.com> <j9q83e$b9m$1@speranza.aioe.org> <4775188.ypaU67uLZW@PointedEars.de>
NNTP-Posting-Host edb3lPNLwDIT/BKKc/Xuzw.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:8.0) Gecko/20111105 Thunderbird/8.0
X-Notice Filtered by postfilter v. 0.8.2
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:8325

Show key headers only | View raw


On 14/11/2011 12:04, Thomas 'PointedEars' Lahn wrote:
> J.R. wrote:
>
>> On 14/11/2011 00:37, Denis McMahon wrote:
>>> On Sun, 13 Nov 2011 20:49:25 -0200, J.R. wrote:
>>>> it is one of the JavaScript best practices to declare all of the
>>>> variables used in a function at the top of the function body. You may
>>>> have many variables separated by commas, e.g
>>>
>>>>      var el = ...,
>>>>          h = ...,
>>>>          w = ...,
>>>>          i, j, len, ..., z;
>>>
>>>> You must not use multiple var statements such as:
>>>>      var el;
>>>>      var h = ...;
>>>>      var z;
>>>
>>> Rubbish.
>>>
>>> You can use as many var statements as you like. Nothing in the standards
>>> or the implementation prevents this, so "must not" is incorrect.
>>
>> "must not" was exaggerated on purpose, because using many var statements
>> is an antipattern in JavaScript.
>
> In your humble opinion (which may not even be your opinion but that of the
> author of some botched book you read instead, and now you think you know the
> language and its "best practices").
>

I still have a long and winding road to go until I get a thorough 
comprehension about JavaScript. But what about you?

>>> Some people think all variables should be declared in a single statement.
>>> Some people use a different statement for each type of variable, where
>>> type is the sort of data that it will be used to hold (array, string,
>>> integer, float, object etc).
>>> Some people just use one variable per var.
>>
>> The advantages of using the Single var Pattern at the top of your
>> functions are:
>
> You are confusing two concepts here.

No, I am not.

>
>> - there's a single place to look for all the local variables needed by
>> the function;
>
> The comma operator does not help with this.
>
>> - prevention of logical errors when a variable is used before it’s
>> defined;
>
> The comma operator does not help with this.
>

Read again and notice that I was writing about adopting the Single var 
Pattern, instead of writing many var statements. It's not about using 
commas.

>> - Helps you remember to declare variables and therefore minimize
>> globals;
>
> The comma …
>
>> - only one var statement means less code to type and a reduction
>> in the file size.
>
> Sometimes.  Because for readable code, you will have to indent the second,
> third aso. line.  In particular, with the style you used above, you do not
> save or add *any* byte.  If this is not obvious to you, look more carefully:
>
>    var.el.=....,.........
>    ....h =....,..........
>    ....w.=....,..........
>    ....i,.j,.len,....,.z;
>
> vs.
>
>    var.el.=....;.........
>    var.h.=....;..........
>    var.w.=....;..........
>    var.i,.j,.len,....,.z;
>

Yes, it is obvious to anyone. But what if we minify our code 
<http://en.wikipedia.org/wiki/Minification_(programming)>, leaving out 
unnecessary spaces? Code Minification is one of the best practices in 
Javascript.

> At any rate, the potential savings are so very small compared to what
> trimming comments, minimization and gzipping can achieve that this is not a
> convincing argument.  Taking my current local object.js as an example:
>
> [snip]
>
> which saves *nothing* with \n =<LF>  but *adds* one byte with \n =<CR><LF>
> as it means removing a space [−1] and adding a newline [+1|+2] on the first
> line, adding two spaces [+2] on the second line, and removing "var" (3 bytes
> [−3]) and adding a space [+1] on the third line).
>
> [snip]
>
> which means removing one space [−1] and adding one newline [+1|+2] on the
> first line, adding one<HT>  [+1] on the second line and saving 3 bytes [−3]
> on the second line (a total of only 1 or two 2 saved bytes).  (However, tab
> indentation may require additional adjustments at the reader's, and is
> therefore also not recommended for posting to Usenet.)

Obviously, you are not considering a file with hundreds, perhaps 
thousands of lines. Code minification is a good practice, supported by 
renowned JS developers and browser-vendors no matter how hard you try to 
deny it just because you want do disqualify my statement. I really think 
that you do not believe in your own words.

>
>>> These are all permitted by the various standards, and they all work.
>>> There is no reason that you "must" or "must not" do any of these.
>>>
>>> Also, "best practice" is invariably "in the opinion of the author of the
>>> website / book / blog / whatever" that said example of best practice
>>> appears in.
>>
>> There are patterns in any programming language usually adopted by
>> programmers as "best coding practices". And it happens to other fields
>> of study too. See<http://en.wikipedia.org/wiki/Best_Coding_Practices>
>>
>> If you get a bunch of authors (books, blogs, etc.) that state the same
>> "best practices" in any programming language, then you can bet who is
>> wrong or right...
>>
>>> As a matter of interest, what's your reference for "best
>>> practice"? If I write a book or start a blog called "Javascript - Best
>>> Practice" does that make it true?
>>
>> No, it doesn't, although I know you're a very experienced and smart
>> programmer. However, if you published some evidence such as performance
>> tests, etc., then you could state that some practice should be either
>> considered a good one or avoided altogether.
>
> Your logic is flawed:<http://en.wikipedia.org/wiki/Ipse_dixit>
>

When there is nothing left to say, you really enjoy finishing a 
discussion off with this sort of Mr. Spock citation (Your logic is 
flawed). Very characteristic.

-- 
Joao Rodrigues (J.R.)

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


Thread

Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 09:51 -0500
  Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-13 18:25 +0100
    Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 13:58 -0500
      Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-13 20:26 +0100
        Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 15:04 -0500
          Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-13 18:55 -0200
            Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-13 18:59 -0200
              Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 17:10 -0500
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-13 20:49 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 20:00 -0500
                Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 02:37 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 03:14 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 14:03 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 14:14 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 18:31 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-11-14 18:36 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-15 00:18 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-14 10:54 -0800
                Re: Difference between findPos("divThis") and findPos(divThis) "Richard Cornford" <Richard@litotes.demon.co.uk> - 2011-11-15 01:23 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-16 06:04 -0800
                Re: Difference between findPos("divThis") and findPos(divThis) Frobernik <nospam@nospam.com> - 2011-11-17 22:06 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-17 23:54 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) Frobernik <nospam@nospam.com> - 2011-11-18 09:33 +0000
                Function arguments vs. local variables (was: Difference between findPos("divThis") and findPos(divThis)) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-19 16:05 +0100
                Re: Function arguments vs. local variables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-19 18:17 +0100
                Re: Function arguments vs. local variables Frobernik <nospam@nospam.com> - 2011-11-21 20:01 +0000
                Re: Function arguments vs. local variables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-22 12:50 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 15:04 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) John G Harris <john@nospam.demon.co.uk> - 2011-11-14 15:13 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 18:27 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-14 17:52 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 15:07 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 18:19 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 15:44 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 19:01 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 16:42 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 19:53 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) Richard Cornford <Richard@litotes.demon.co.uk> - 2011-11-14 09:18 -0800
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 16:22 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 18:38 +0000
                Re: Difference between findPos("divThis") and findPos(divThis) Gene Wirchenko <genew@ocis.net> - 2011-11-14 12:12 -0800
                Re: Difference between findPos("divThis") and findPos(divThis) Gene Wirchenko <genew@ocis.net> - 2011-11-14 12:00 -0800
                Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-14 08:48 -0500
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 13:15 +0100
                Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 13:03 -0200
                Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 17:24 +0100
          Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 13:00 +0100
        Re: Difference between findPos("divThis") and findPos(divThis) John G Harris <john@nospam.demon.co.uk> - 2011-11-14 15:05 +0000

csiph-web