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

2983Re: [jslint] Re: Array construction bug

Expand Messages
  • Martin Cooper
    Aug 31, 2012
    • 0 Attachment
      On Fri, Aug 31, 2012 at 7:41 AM, Alexandre Morgaut <morgaut@...> wrote:
      > --- In jslint_com@yahoogroups.com, Luke Page <luke.a.page@...> wrote:
      >>
      >> > If I want to create, say, a separator line of 'len' dashes, I can do
      >> > that really cleanly and easily with:
      >> >
      >> > var separator = Array(len).join('-');
      >> >
      >>
      >> Wouldn't it be clearer and more maintainable to create a function for it
      >> anyway?
      >>
      >> var seperator = repeatString('-', len);
      >>
      >> it doesn't look as "clever" to use a for loop to concatenate, but is there
      >> a noticeable performance loss? Is it easier to read and understand?
      >
      > I think that it's more maintainable and more secure to use a dedicated function
      > One going to the code using the Array constructor might expect that the numebr of characters in the string will be len while it will be (len -1). And even if he take care of that it will mean that most of the time the one line will be:
      >
      > var str = Array(nbChars + 1).join(char);
      >
      > It will then become ever less obvious to understand what this code is for compared to
      >
      > var str = repeatString(char, nbChars);
      >
      > One of the goals of JSLint is to make your code more maintainable by anyone (even you some some few years...)

      Right. So I personally find that taking advantage of what the language
      has to offer helps me do that. If I have to write a function, document
      it, and write unit tests for it, have I really improved the ability to
      maintain my code, over using the language the way it was designed?

      In my case, I'm writing code for professional JavaScript developers,
      not noobs. I want JSLint to help me find bugs, not tell me I have to
      dumb down my code for people who don't understand the language. Having
      a warning that I can turn off if I want to use a language feature is
      fine; providing no way to get past JSLint while using a perfectly
      legal language feature is not.

      --
      Martin Cooper


      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
    • Show all 21 messages in this topic