Loading ...
Sorry, an error occurred while loading the content.

2876Re: [jslint] Nested loops with the same control vars

Expand Messages
  • John Hawkinson
    May 9, 2012
    • 0 Attachment
      Rob Richardson <erobrich@...> wrote on Wed, 9 May 2012
      at 11:16:11 -0700 in <003a01cd2e0f$d0f95240$72ebf6c0$@...>:

      > I think an even larger issue should be checking for identically named
      > variables declared in different scope.

      I don't agree.

      i is a common counter variable. It is reasonable style to use i
      as the primary counter variable in all non-nested for loops.
      It's quite fine for an outer function to use 'i' as counter for its
      for loops even when an inner helper function also uses' i' as a counter
      for its for loops. In fact, arguably it is best -- otherwise it means
      the programmer has to worry about what all the helper functions are
      within an outer function and what all their variables are. And if they
      must be treated as coming from the same space, it's almost like we
      didn't have nested function scope at all!

      I think it would be reasonable to warn when a function-local variable
      masks another variable iwth the same name, because it certainly can
      be an error. But it need not be, and non-nested for loop counter
      variables, I don't think it's an error, I think its actually good style.

      I do not want to think about what all the local variables used by the
      functions I call are. And I should not have to.

      John Hawkinson

      > This too should be illegal:
      > function a() {
      > ````var i;
      > ````function b() {
      > ````````var i;
      > ````};
      > };
    • Show all 5 messages in this topic